User prompt
far from each other remove
User prompt
Put worker, warrior, wizard and dragon recruitment at the bottom of the screen
User prompt
Each team should have only one tower
User prompt
Both teams start with 0 coins and each team has 1 worker at the beginning and each team has a tower
Code edit (1 edits merged)
Please save this source code
User prompt
Tower Defense: Coin Wars
Initial prompt
Make a tower defense game. In this game, there is a us and an AI. There are towers at the bottom, middle and top middle of the screen. Coins appear randomly around and the worker character tries to collect these coins. For each coin collected, 1 coin goes to that team. Let's try to summon new workers, warriors, wizards and dragons with those coins. The wizard, warrior and dragon try to attack the towers. Workers have 5 coins, warriors have 7 coins, wizards have 10 coins and the dragon has 20 coins.
/**** * Classes ****/ var Coin = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.value = 1; self.collected = false; return self; }); var CombatUnit = Container.expand(function (team, unitType) { var self = Container.call(this); var assetName = team === 'player' ? unitType : 'ai' + unitType.charAt(0).toUpperCase() + unitType.slice(1); var graphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.team = team; self.unitType = unitType; self.speed = unitType === 'dragon' ? 3 : unitType === 'wizard' ? 1.5 : 2; self.damage = unitType === 'dragon' ? 25 : unitType === 'wizard' ? 15 : 10; self.health = unitType === 'dragon' ? 60 : unitType === 'wizard' ? 30 : 40; self.maxHealth = self.health; self.attackRange = unitType === 'wizard' ? 100 : 50; self.attackCooldown = 0; self.target = null; self.update = function () { if (self.attackCooldown > 0) { self.attackCooldown--; } if (!self.target) { self.findNearestEnemyTower(); } else { self.moveToTarget(); } }; self.findNearestEnemyTower = function () { var enemyTowers = self.team === 'player' ? aiTowers : playerTowers; var nearestTower = null; var nearestDistance = Infinity; for (var i = 0; i < enemyTowers.length; i++) { var tower = enemyTowers[i]; var distance = Math.sqrt(Math.pow(tower.x - self.x, 2) + Math.pow(tower.y - self.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestTower = tower; } } self.target = nearestTower; }; self.moveToTarget = function () { if (!self.target) { return; } var dx = self.target.x - self.x; var dy = self.target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < self.attackRange) { self.attackTarget(); } else { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; self.attackTarget = function () { if (self.attackCooldown <= 0 && self.target) { self.target.health -= self.damage; self.attackCooldown = 60; LK.getSound('attack').play(); if (self.target.health <= 0) { self.destroyTower(); } } }; self.destroyTower = function () { var towers = self.team === 'player' ? aiTowers : playerTowers; var index = towers.indexOf(self.target); if (index > -1) { towers.splice(index, 1); self.target.destroy(); LK.getSound('towerDestroyed').play(); self.target = null; } }; return self; }); var Tower = Container.expand(function (team) { var self = Container.call(this); var assetName = team === 'player' ? 'playerTower' : 'aiTower'; var graphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 1.0 }); self.team = team; self.health = 100; self.maxHealth = 100; return self; }); var Worker = Container.expand(function (team) { var self = Container.call(this); var assetName = team === 'player' ? 'worker' : 'aiWorker'; var graphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.team = team; self.speed = 2; self.target = null; self.collectRange = 40; self.update = function () { if (!self.target) { self.findNearestCoin(); } else { self.moveToTarget(); } }; self.findNearestCoin = function () { var nearestCoin = null; var nearestDistance = Infinity; for (var i = 0; i < coins.length; i++) { var coin = coins[i]; if (!coin.collected) { var distance = Math.sqrt(Math.pow(coin.x - self.x, 2) + Math.pow(coin.y - self.y, 2)); if (distance < nearestDistance) { nearestDistance = distance; nearestCoin = coin; } } } self.target = nearestCoin; }; self.moveToTarget = function () { if (!self.target || self.target.collected) { self.target = null; return; } var dx = self.target.x - self.x; var dy = self.target.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < self.collectRange) { self.collectCoin(); } else { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; self.collectCoin = function () { if (self.target && !self.target.collected) { self.target.collected = true; if (self.team === 'player') { playerCoins += self.target.value; } else { aiCoins += self.target.value; } LK.getSound('coinCollect').play(); self.target = null; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ var playerCoins = 0; var aiCoins = 0; var playerTowers = []; var aiTowers = []; var coins = []; var playerUnits = []; var aiUnits = []; var coinSpawnTimer = 0; var aiActionTimer = 0; // UI Elements var coinDisplay = new Text2('Coins: 0', { size: 40, fill: '#ffffff' }); coinDisplay.anchor.set(0, 0); LK.gui.topLeft.addChild(coinDisplay); var workerButton = new Text2('Worker (5)', { size: 30, fill: '#00ff00' }); workerButton.anchor.set(0.5, 0.5); workerButton.x = -150; workerButton.y = -50; LK.gui.bottom.addChild(workerButton); var warriorButton = new Text2('Warrior (7)', { size: 30, fill: '#8B4513' }); warriorButton.anchor.set(0.5, 0.5); warriorButton.x = -50; warriorButton.y = -50; LK.gui.bottom.addChild(warriorButton); var wizardButton = new Text2('Wizard (10)', { size: 30, fill: '#9932cc' }); wizardButton.anchor.set(0.5, 0.5); wizardButton.x = 50; wizardButton.y = -50; LK.gui.bottom.addChild(wizardButton); var dragonButton = new Text2('Dragon (20)', { size: 30, fill: '#ff6600' }); dragonButton.anchor.set(0.5, 0.5); dragonButton.x = 150; dragonButton.y = -50; LK.gui.bottom.addChild(dragonButton); // Initialize towers function initializeTowers() { // Player tower var playerTower = new Tower('player'); playerTower.x = 1024; playerTower.y = 2600; playerTowers.push(playerTower); game.addChild(playerTower); // AI tower var aiTower = new Tower('ai'); aiTower.x = 1024; aiTower.y = 300; aiTowers.push(aiTower); game.addChild(aiTower); } ; function spawnCoin() { var coin = new Coin(); coin.x = Math.random() * 1800 + 124; coin.y = Math.random() * 2000 + 400; coins.push(coin); game.addChild(coin); } function spawnUnit(team, unitType) { var unit; var cost = unitType === 'worker' ? 5 : unitType === 'warrior' ? 7 : unitType === 'wizard' ? 10 : 20; if (team === 'player' && playerCoins >= cost) { playerCoins -= cost; if (unitType === 'worker') { unit = new Worker('player'); } else { unit = new CombatUnit('player', unitType); } unit.x = Math.random() * 400 + 800; unit.y = 2400; playerUnits.push(unit); game.addChild(unit); LK.getSound('unitSpawn').play(); } else if (team === 'ai' && aiCoins >= cost) { aiCoins -= cost; if (unitType === 'worker') { unit = new Worker('ai'); } else { unit = new CombatUnit('ai', unitType); } unit.x = Math.random() * 400 + 800; unit.y = 500; aiUnits.push(unit); game.addChild(unit); } } function aiLogic() { if (aiActionTimer <= 0) { if (aiCoins >= 20 && Math.random() < 0.1) { spawnUnit('ai', 'dragon'); } else if (aiCoins >= 10 && Math.random() < 0.2) { spawnUnit('ai', 'wizard'); } else if (aiCoins >= 7 && Math.random() < 0.3) { spawnUnit('ai', 'warrior'); } else if (aiCoins >= 5 && Math.random() < 0.4) { spawnUnit('ai', 'worker'); } aiActionTimer = 120; } aiActionTimer--; } function checkGameEnd() { if (playerTowers.length === 0) { LK.showGameOver(); } else if (aiTowers.length === 0) { LK.showYouWin(); } } function cleanupCollectedCoins() { for (var i = coins.length - 1; i >= 0; i--) { if (coins[i].collected) { coins[i].destroy(); coins.splice(i, 1); } } } // Button event handlers workerButton.down = function () { spawnUnit('player', 'worker'); }; warriorButton.down = function () { spawnUnit('player', 'warrior'); }; wizardButton.down = function () { spawnUnit('player', 'wizard'); }; dragonButton.down = function () { spawnUnit('player', 'dragon'); }; // Initialize game initializeTowers(); // Spawn initial workers for both teams var playerWorker = new Worker('player'); playerWorker.x = 1024; playerWorker.y = 2300; playerUnits.push(playerWorker); game.addChild(playerWorker); var aiWorker = new Worker('ai'); aiWorker.x = 1024; aiWorker.y = 600; aiUnits.push(aiWorker); game.addChild(aiWorker); // Main game loop game.update = function () { // Update coin display coinDisplay.setText('Coins: ' + playerCoins); // Spawn coins coinSpawnTimer++; if (coinSpawnTimer >= 180) { spawnCoin(); coinSpawnTimer = 0; } // AI logic aiLogic(); // Clean up collected coins cleanupCollectedCoins(); // Check game end conditions checkGameEnd(); };
===================================================================
--- original.js
+++ change.js
@@ -192,35 +192,35 @@
size: 30,
fill: '#00ff00'
});
workerButton.anchor.set(0.5, 0.5);
-workerButton.x = 200;
-workerButton.y = 200;
-LK.gui.bottomLeft.addChild(workerButton);
+workerButton.x = -150;
+workerButton.y = -50;
+LK.gui.bottom.addChild(workerButton);
var warriorButton = new Text2('Warrior (7)', {
size: 30,
fill: '#8B4513'
});
warriorButton.anchor.set(0.5, 0.5);
-warriorButton.x = 200;
-warriorButton.y = 150;
-LK.gui.bottomLeft.addChild(warriorButton);
+warriorButton.x = -50;
+warriorButton.y = -50;
+LK.gui.bottom.addChild(warriorButton);
var wizardButton = new Text2('Wizard (10)', {
size: 30,
fill: '#9932cc'
});
wizardButton.anchor.set(0.5, 0.5);
-wizardButton.x = 200;
-wizardButton.y = 100;
-LK.gui.bottomLeft.addChild(wizardButton);
+wizardButton.x = 50;
+wizardButton.y = -50;
+LK.gui.bottom.addChild(wizardButton);
var dragonButton = new Text2('Dragon (20)', {
size: 30,
fill: '#ff6600'
});
dragonButton.anchor.set(0.5, 0.5);
-dragonButton.x = 200;
-dragonButton.y = 50;
-LK.gui.bottomLeft.addChild(dragonButton);
+dragonButton.x = 150;
+dragonButton.y = -50;
+LK.gui.bottom.addChild(dragonButton);
// Initialize towers
function initializeTowers() {
// Player tower
var playerTower = new Tower('player');
Worker. In-Game asset. 2d. High contrast. No shadows
Wizard. In-Game asset. 2d. High contrast. No shadows
Dragon. In-Game asset. 2d. High contrast. No shadows
Warrior. In-Game asset. 2d. High contrast. No shadows
etrafı kırmızı işçi. In-Game asset. 2d. High contrast. No shadows
Archer. In-Game asset. 2d. High contrast. No shadows
Magic. In-Game asset. 2d. High contrast. No shadows
Sadece 1 Altın parçacığı. In-Game asset. 2d. High contrast. No shadows
Köşelerdeki taş yerleri kaldır
Çözünürlüğü artır ve kırmızı şeyleri kaldır. In-Game asset. 2d. High contrast. No shadows
Ağzından ateş püskürtsün
Tam yukarıdan bakılan bir kule clash royaledeki gibi. In-Game asset. 2d. High contrast. No shadows
Mavi yerler kırmızı olsun
Sol tarafında kılıçlar olan start buton. In-Game asset. 2d. High contrast. No shadows
How to play button. In-Game asset. 2d. High contrast. No shadows
Tower defence menü background. In-Game asset. 2d. High contrast. No shadows
Towers On Attack yazısı. In-Game asset. 2d. High contrast. No shadows
Zombie. In-Game asset. 2d. High contrast. No shadows
Normal Mode button. In-Game asset. 2d. High contrast. No shadows
Zombie Mode buton. In-Game asset. 2d. High contrast. No shadows