User prompt
ai replaces laws that are active
User prompt
when a law is active new law takes spot ai law generation and effects
User prompt
add new things like you can make laws that ai generated there are revolutions economy....
Code edit (1 edits merged)
Please save this source code
User prompt
War Economy Tycoon
Initial prompt
war+ money+ guns+ buying soldiers+ army's+opposing armies+government+laws+plagues+revolutions
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Unit = Container.expand(function () { var self = Container.call(this); self.type = 'infantry'; self.health = 100; self.maxHealth = 100; self.damage = 10; self.cost = 50; self.isEnemy = false; self.targetX = 0; self.targetY = 0; self.speed = 1; self.takeDamage = function (amount) { self.health -= amount; if (self.health <= 0) { self.health = 0; return true; // Unit died } return false; }; self.moveToward = function (x, y) { var dx = x - self.x; var dy = y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 5) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; return self; }); var Infantry = Unit.expand(function () { var self = Unit.call(this); var graphics = self.attachAsset('soldier', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'infantry'; self.health = 100; self.maxHealth = 100; self.damage = 15; self.cost = 50; self.speed = 1.5; return self; }); var EnemyUnit = Unit.expand(function () { var self = Unit.call(this); self.isEnemy = true; return self; }); var EnemyInfantry = EnemyUnit.expand(function () { var self = EnemyUnit.call(this); var graphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'infantry'; self.health = 100; self.maxHealth = 100; self.damage = 12; self.speed = 1.3; return self; }); var EnemyCavalry = EnemyUnit.expand(function () { var self = EnemyUnit.call(this); var graphics = self.attachAsset('enemyCavalry', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'cavalry'; self.health = 140; self.maxHealth = 140; self.damage = 22; self.speed = 2.8; return self; }); var EnemyArtillery = EnemyUnit.expand(function () { var self = EnemyUnit.call(this); var graphics = self.attachAsset('enemyArtillery', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'artillery'; self.health = 75; self.maxHealth = 75; self.damage = 35; self.speed = 0.7; return self; }); var Cavalry = Unit.expand(function () { var self = Unit.call(this); var graphics = self.attachAsset('cavalry', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'cavalry'; self.health = 150; self.maxHealth = 150; self.damage = 25; self.cost = 100; self.speed = 3; return self; }); var Artillery = Unit.expand(function () { var self = Unit.call(this); var graphics = self.attachAsset('artillery', { anchorX: 0.5, anchorY: 0.5 }); self.type = 'artillery'; self.health = 80; self.maxHealth = 80; self.damage = 40; self.cost = 200; self.speed = 0.8; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // Game state variables var money = storage.money || 1000; var playerUnits = []; var enemyUnits = []; var gameState = 'menu'; // menu, battle, event var battleTimer = 0; var eventTimer = 0; var waveNumber = 1; var lastEventTime = 0; // Unit costs (affected by events) var unitCosts = { infantry: 50, cavalry: 100, artillery: 200 }; // Law system var activeLaws = []; var lawTypes = [{ name: 'Military Conscription', description: 'Reduce infantry cost by 30%', cost: 500, effect: function effect() { unitCosts.infantry = Math.floor(unitCosts.infantry * 0.7); }, active: false }, { name: 'Arms Manufacturing', description: 'Reduce artillery cost by 25%', cost: 800, effect: function effect() { unitCosts.artillery = Math.floor(unitCosts.artillery * 0.75); }, active: false }, { name: 'Trade Agreements', description: 'Increase passive income by 100%', cost: 1000, effect: function effect() { // Effect handled in passive income section }, active: false }, { name: 'War Economy', description: 'All units cost 20% more but deal 50% more damage', cost: 1200, effect: function effect() { unitCosts.infantry = Math.floor(unitCosts.infantry * 1.2); unitCosts.cavalry = Math.floor(unitCosts.cavalry * 1.2); unitCosts.artillery = Math.floor(unitCosts.artillery * 1.2); // Damage boost handled in combat }, active: false }]; // Event system var activeEvents = []; var eventTypes = [{ name: 'Plague', description: 'A plague reduces all unit health by 20%', effect: function effect() { for (var i = 0; i < playerUnits.length; i++) { playerUnits[i].health = Math.max(1, Math.floor(playerUnits[i].health * 0.8)); } } }, { name: 'Revolution', description: 'Economic upheaval reduces income by 30%', effect: function effect() { money = Math.floor(money * 0.7); // Revolution also disables all active laws for (var i = 0; i < lawTypes.length; i++) { lawTypes[i].active = false; } activeLaws = []; resetUnitCosts(); } }, { name: 'Military Reform', description: 'Government increases unit costs by 50%', effect: function effect() { unitCosts.infantry = Math.floor(unitCosts.infantry * 1.5); unitCosts.cavalry = Math.floor(unitCosts.cavalry * 1.5); unitCosts.artillery = Math.floor(unitCosts.artillery * 1.5); } }, { name: 'Government Coup', description: 'New government allows creation of beneficial laws', effect: function effect() { // Reset all laws to available for (var i = 0; i < lawTypes.length; i++) { lawTypes[i].active = false; } activeLaws = []; resetUnitCosts(); } }]; // UI Elements var moneyText = new Text2(money.toString(), { size: 60, fill: 0xFFFFFF }); moneyText.anchor.set(0, 0); LK.gui.top.addChild(moneyText); moneyText.x = 200; moneyText.y = 20; var waveText = new Text2('Wave: ' + waveNumber, { size: 50, fill: 0xFFFFFF }); waveText.anchor.set(0.5, 0); LK.gui.top.addChild(waveText); var eventText = new Text2('', { size: 40, fill: 0xFF6B6B }); eventText.anchor.set(0.5, 0.5); LK.gui.center.addChild(eventText); // Buy buttons var infantryButton = new Text2('Infantry ($' + unitCosts.infantry + ')', { size: 45, fill: 0x4A90E2 }); infantryButton.anchor.set(0, 1); LK.gui.bottomLeft.addChild(infantryButton); infantryButton.x = 50; infantryButton.y = -200; var cavalryButton = new Text2('Cavalry ($' + unitCosts.cavalry + ')', { size: 45, fill: 0x7ED321 }); cavalryButton.anchor.set(0, 1); LK.gui.bottomLeft.addChild(cavalryButton); cavalryButton.x = 50; cavalryButton.y = -150; var artilleryButton = new Text2('Artillery ($' + unitCosts.artillery + ')', { size: 45, fill: 0xD0021B }); artilleryButton.anchor.set(0, 1); LK.gui.bottomLeft.addChild(artilleryButton); artilleryButton.x = 50; artilleryButton.y = -100; var startBattleButton = new Text2('Start Battle', { size: 50, fill: 0xF39C12 }); startBattleButton.anchor.set(0.5, 1); LK.gui.bottom.addChild(startBattleButton); startBattleButton.y = -50; // Laws UI var lawsTitle = new Text2('LAWS', { size: 40, fill: 0xE74C3C }); lawsTitle.anchor.set(1, 0); LK.gui.topRight.addChild(lawsTitle); lawsTitle.x = -50; lawsTitle.y = 20; var lawButtons = []; for (var i = 0; i < lawTypes.length; i++) { var lawButton = new Text2(lawTypes[i].name + ' ($' + lawTypes[i].cost + ')', { size: 35, fill: 0x95A5A6 }); lawButton.anchor.set(1, 0); LK.gui.topRight.addChild(lawButton); lawButton.x = -50; lawButton.y = 80 + i * 60; lawButton.lawIndex = i; lawButtons.push(lawButton); } // Functions function updateMoney() { moneyText.setText('$' + money); storage.money = money; } function updateButtonTexts() { infantryButton.setText('Infantry ($' + unitCosts.infantry + ')'); cavalryButton.setText('Cavalry ($' + unitCosts.cavalry + ')'); artilleryButton.setText('Artillery ($' + unitCosts.artillery + ')'); } function resetUnitCosts() { unitCosts.infantry = 50; unitCosts.cavalry = 100; unitCosts.artillery = 200; } function applyAllActiveLaws() { resetUnitCosts(); for (var i = 0; i < activeLaws.length; i++) { activeLaws[i].effect(); } updateButtonTexts(); } function enactLaw(lawIndex) { var law = lawTypes[lawIndex]; if (!law.active && money >= law.cost) { money -= law.cost; law.active = true; activeLaws.push(law); applyAllActiveLaws(); updateMoney(); updateLawButtons(); eventText.setText('Law Enacted: ' + law.name); LK.getSound('event').play(); LK.setTimeout(function () { eventText.setText(''); }, 2000); } } function updateLawButtons() { for (var i = 0; i < lawButtons.length; i++) { var law = lawTypes[i]; var button = lawButtons[i]; if (law.active) { button.fill = 0x27AE60; button.setText(law.name + ' (ACTIVE)'); } else { button.fill = money >= law.cost ? 0x3498DB : 0x95A5A6; button.setText(law.name + ' ($' + law.cost + ')'); } } } function buyUnit(type) { var cost = unitCosts[type]; if (money >= cost) { money -= cost; updateMoney(); var unit; if (type === 'infantry') { unit = new Infantry(); } else if (type === 'cavalry') { unit = new Cavalry(); } else if (type === 'artillery') { unit = new Artillery(); } unit.x = 200 + Math.random() * 400; unit.y = 2000 + Math.random() * 200; playerUnits.push(unit); game.addChild(unit); LK.getSound('purchase').play(); } } function spawnEnemyWave() { var enemyCount = waveNumber + 2; for (var i = 0; i < enemyCount; i++) { var enemy; var rand = Math.random(); if (rand < 0.6) { enemy = new EnemyInfantry(); } else if (rand < 0.8) { enemy = new EnemyCavalry(); } else { enemy = new EnemyArtillery(); } enemy.x = 800 + Math.random() * 800; enemy.y = 500 + Math.random() * 200; enemyUnits.push(enemy); game.addChild(enemy); } } function startBattle() { if (playerUnits.length === 0) return; gameState = 'battle'; battleTimer = 0; spawnEnemyWave(); LK.getSound('battle').play(); } function triggerRandomEvent() { if (Math.random() < 0.3 && LK.ticks - lastEventTime > 1800) { // 30 seconds var eventIndex = Math.floor(Math.random() * eventTypes.length); var event = eventTypes[eventIndex]; eventText.setText(event.name + ': ' + event.description); event.effect(); updateButtonTexts(); LK.getSound('event').play(); lastEventTime = LK.ticks; // Clear event text after 3 seconds LK.setTimeout(function () { eventText.setText(''); }, 3000); } } function findNearestEnemy(unit) { var nearest = null; var nearestDistance = Infinity; var targets = unit.isEnemy ? playerUnits : enemyUnits; for (var i = 0; i < targets.length; i++) { var target = targets[i]; var dx = target.x - unit.x; var dy = target.y - unit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < nearestDistance) { nearestDistance = distance; nearest = target; } } return nearest; } function updateBattle() { // Move and attack player units for (var i = playerUnits.length - 1; i >= 0; i--) { var unit = playerUnits[i]; var target = findNearestEnemy(unit); if (target) { var dx = target.x - unit.x; var dy = target.y - unit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 100) { unit.moveToward(target.x, target.y); } else if (battleTimer % 60 === 0) { // Attack once per second var damage = unit.damage; // Check if War Economy law is active for (var j = 0; j < activeLaws.length; j++) { if (activeLaws[j].name === 'War Economy') { damage = Math.floor(damage * 1.5); break; } } var killed = target.takeDamage(damage); if (killed) { var targetIndex = enemyUnits.indexOf(target); if (targetIndex !== -1) { enemyUnits[targetIndex].destroy(); enemyUnits.splice(targetIndex, 1); money += 25; // Reward for killing enemy updateMoney(); } } } } } // Move and attack enemy units for (var i = enemyUnits.length - 1; i >= 0; i--) { var unit = enemyUnits[i]; var target = findNearestEnemy(unit); if (target) { var dx = target.x - unit.x; var dy = target.y - unit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 100) { unit.moveToward(target.x, target.y); } else if (battleTimer % 60 === 0) { // Attack once per second var killed = target.takeDamage(unit.damage); if (killed) { var targetIndex = playerUnits.indexOf(target); if (targetIndex !== -1) { playerUnits[targetIndex].destroy(); playerUnits.splice(targetIndex, 1); } } } } } // Check battle end conditions if (enemyUnits.length === 0) { // Player won gameState = 'menu'; waveNumber++; waveText.setText('Wave: ' + waveNumber); money += 100 * waveNumber; // Wave completion bonus updateMoney(); } else if (playerUnits.length === 0) { // Player lost LK.showGameOver(); } } // Event handlers infantryButton.down = function () { buyUnit('infantry'); }; cavalryButton.down = function () { buyUnit('cavalry'); }; artilleryButton.down = function () { buyUnit('artillery'); }; startBattleButton.down = function () { if (gameState === 'menu') { startBattle(); } }; // Law button handlers for (var i = 0; i < lawButtons.length; i++) { lawButtons[i].down = function (index) { return function () { enactLaw(index); }; }(i); } // Main game update loop game.update = function () { if (gameState === 'battle') { battleTimer++; updateBattle(); } // Passive income every 3 seconds if (LK.ticks % 180 === 0) { var income = 50; // Check if Trade Agreements law is active for (var i = 0; i < activeLaws.length; i++) { if (activeLaws[i].name === 'Trade Agreements') { income *= 2; break; } } money += income; updateMoney(); } // Trigger random events triggerRandomEvent(); // Update law button states updateLawButtons(); // Check for bankruptcy if (money < 0) { LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -148,8 +148,46 @@
infantry: 50,
cavalry: 100,
artillery: 200
};
+// Law system
+var activeLaws = [];
+var lawTypes = [{
+ name: 'Military Conscription',
+ description: 'Reduce infantry cost by 30%',
+ cost: 500,
+ effect: function effect() {
+ unitCosts.infantry = Math.floor(unitCosts.infantry * 0.7);
+ },
+ active: false
+}, {
+ name: 'Arms Manufacturing',
+ description: 'Reduce artillery cost by 25%',
+ cost: 800,
+ effect: function effect() {
+ unitCosts.artillery = Math.floor(unitCosts.artillery * 0.75);
+ },
+ active: false
+}, {
+ name: 'Trade Agreements',
+ description: 'Increase passive income by 100%',
+ cost: 1000,
+ effect: function effect() {
+ // Effect handled in passive income section
+ },
+ active: false
+}, {
+ name: 'War Economy',
+ description: 'All units cost 20% more but deal 50% more damage',
+ cost: 1200,
+ effect: function effect() {
+ unitCosts.infantry = Math.floor(unitCosts.infantry * 1.2);
+ unitCosts.cavalry = Math.floor(unitCosts.cavalry * 1.2);
+ unitCosts.artillery = Math.floor(unitCosts.artillery * 1.2);
+ // Damage boost handled in combat
+ },
+ active: false
+}];
// Event system
var activeEvents = [];
var eventTypes = [{
name: 'Plague',
@@ -163,8 +201,14 @@
name: 'Revolution',
description: 'Economic upheaval reduces income by 30%',
effect: function effect() {
money = Math.floor(money * 0.7);
+ // Revolution also disables all active laws
+ for (var i = 0; i < lawTypes.length; i++) {
+ lawTypes[i].active = false;
+ }
+ activeLaws = [];
+ resetUnitCosts();
}
}, {
name: 'Military Reform',
description: 'Government increases unit costs by 50%',
@@ -172,8 +216,19 @@
unitCosts.infantry = Math.floor(unitCosts.infantry * 1.5);
unitCosts.cavalry = Math.floor(unitCosts.cavalry * 1.5);
unitCosts.artillery = Math.floor(unitCosts.artillery * 1.5);
}
+}, {
+ name: 'Government Coup',
+ description: 'New government allows creation of beneficial laws',
+ effect: function effect() {
+ // Reset all laws to available
+ for (var i = 0; i < lawTypes.length; i++) {
+ lawTypes[i].active = false;
+ }
+ activeLaws = [];
+ resetUnitCosts();
+ }
}];
// UI Elements
var moneyText = new Text2(money.toString(), {
size: 60,
@@ -226,8 +281,30 @@
});
startBattleButton.anchor.set(0.5, 1);
LK.gui.bottom.addChild(startBattleButton);
startBattleButton.y = -50;
+// Laws UI
+var lawsTitle = new Text2('LAWS', {
+ size: 40,
+ fill: 0xE74C3C
+});
+lawsTitle.anchor.set(1, 0);
+LK.gui.topRight.addChild(lawsTitle);
+lawsTitle.x = -50;
+lawsTitle.y = 20;
+var lawButtons = [];
+for (var i = 0; i < lawTypes.length; i++) {
+ var lawButton = new Text2(lawTypes[i].name + ' ($' + lawTypes[i].cost + ')', {
+ size: 35,
+ fill: 0x95A5A6
+ });
+ lawButton.anchor.set(1, 0);
+ LK.gui.topRight.addChild(lawButton);
+ lawButton.x = -50;
+ lawButton.y = 80 + i * 60;
+ lawButton.lawIndex = i;
+ lawButtons.push(lawButton);
+}
// Functions
function updateMoney() {
moneyText.setText('$' + money);
storage.money = money;
@@ -236,8 +313,49 @@
infantryButton.setText('Infantry ($' + unitCosts.infantry + ')');
cavalryButton.setText('Cavalry ($' + unitCosts.cavalry + ')');
artilleryButton.setText('Artillery ($' + unitCosts.artillery + ')');
}
+function resetUnitCosts() {
+ unitCosts.infantry = 50;
+ unitCosts.cavalry = 100;
+ unitCosts.artillery = 200;
+}
+function applyAllActiveLaws() {
+ resetUnitCosts();
+ for (var i = 0; i < activeLaws.length; i++) {
+ activeLaws[i].effect();
+ }
+ updateButtonTexts();
+}
+function enactLaw(lawIndex) {
+ var law = lawTypes[lawIndex];
+ if (!law.active && money >= law.cost) {
+ money -= law.cost;
+ law.active = true;
+ activeLaws.push(law);
+ applyAllActiveLaws();
+ updateMoney();
+ updateLawButtons();
+ eventText.setText('Law Enacted: ' + law.name);
+ LK.getSound('event').play();
+ LK.setTimeout(function () {
+ eventText.setText('');
+ }, 2000);
+ }
+}
+function updateLawButtons() {
+ for (var i = 0; i < lawButtons.length; i++) {
+ var law = lawTypes[i];
+ var button = lawButtons[i];
+ if (law.active) {
+ button.fill = 0x27AE60;
+ button.setText(law.name + ' (ACTIVE)');
+ } else {
+ button.fill = money >= law.cost ? 0x3498DB : 0x95A5A6;
+ button.setText(law.name + ' ($' + law.cost + ')');
+ }
+ }
+}
function buyUnit(type) {
var cost = unitCosts[type];
if (money >= cost) {
money -= cost;
@@ -326,9 +444,17 @@
if (distance > 100) {
unit.moveToward(target.x, target.y);
} else if (battleTimer % 60 === 0) {
// Attack once per second
- var killed = target.takeDamage(unit.damage);
+ var damage = unit.damage;
+ // Check if War Economy law is active
+ for (var j = 0; j < activeLaws.length; j++) {
+ if (activeLaws[j].name === 'War Economy') {
+ damage = Math.floor(damage * 1.5);
+ break;
+ }
+ }
+ var killed = target.takeDamage(damage);
if (killed) {
var targetIndex = enemyUnits.indexOf(target);
if (targetIndex !== -1) {
enemyUnits[targetIndex].destroy();
@@ -390,21 +516,39 @@
if (gameState === 'menu') {
startBattle();
}
};
+// Law button handlers
+for (var i = 0; i < lawButtons.length; i++) {
+ lawButtons[i].down = function (index) {
+ return function () {
+ enactLaw(index);
+ };
+ }(i);
+}
// Main game update loop
game.update = function () {
if (gameState === 'battle') {
battleTimer++;
updateBattle();
}
// Passive income every 3 seconds
if (LK.ticks % 180 === 0) {
- money += 50;
+ var income = 50;
+ // Check if Trade Agreements law is active
+ for (var i = 0; i < activeLaws.length; i++) {
+ if (activeLaws[i].name === 'Trade Agreements') {
+ income *= 2;
+ break;
+ }
+ }
+ money += income;
updateMoney();
}
// Trigger random events
triggerRandomEvent();
+ // Update law button states
+ updateLawButtons();
// Check for bankruptcy
if (money < 0) {
LK.showGameOver();
}