User prompt
Please fix the bug: 'guiSoldierCostTxt is not defined' in or related to this line: 'guiSoldierCostTxt.x = playerGoldTxt.x - 30;' Line Number: 567
User prompt
remove "soldier 100 gold" "cavalry 120 gold"
User prompt
I'm increasing the price of archer player archer enemy from 120 gold to 150 gold
User prompt
'150 G' text should appear when the castle is raised
User prompt
solder_button write "100 G" under it
User prompt
archer_button write "150 G" under it
User prompt
solder_button write "100G" under it
User prompt
remove the writing on the castle "soldier 100 gold" "cavalry 120 gold"
User prompt
on the left side of the tan score "soldier 100 gold" "cavalry 120 gold" it should be written
User prompt
on the castle "soldier 100 gold" "cavalry 120 gold" it should be written
User prompt
archer_button and solder_button should be side by side on the left side of the screen and visible on the screen.
User prompt
archer_button and solder_button be closer to the left
User prompt
"YOU NEED 350 GOLD TO UPGRADE." LET THIS TEXT BE PERISHED AFTER RISING THE CASTLE.
User prompt
IN HARD MODE, THERE IS NO NEED TO SPEND GOLD TO UPGRADE THE ENEMY AND CASTLE.
User prompt
IN HARD MODE, THERE IS NO NEED TO SPEND GOLD TO UPGRADE THE ENEMY AND CASTLE.
User prompt
"YOU NEED 350 GOLD TO UPGRADE." A LITTLE MORE ON THE RIGHT SIDE
User prompt
LET IT SAY "GOLD" NEXT TO THE GOLD AMOUNT, LET IT SAY "LIFE" NEXT TO THE CASTLE'S LIFE VALUE, ALSO IN BLACK
User prompt
"YOU NEED 350 GOLD TO UPGRADE." LET THIS TEXT BE BLACK AND WRITE IN TWO LINES
User prompt
WRITE "YOU NEED 350 GOLD TO UPGRADE" UNDER THE PLAYER'S CASTLE
User prompt
The castle upgrade cost is 350 gold, take out 200 gold for the enemy and upgrade it after sending 10 soldier_enemy, of course you should save and spend your gold
User prompt
Increase castle upgrade cost from 500 gold to 350 gold for both enemy and player
User prompt
Increase castle upgrade cost from 150 gold to 500 gold for both enemy and player
User prompt
archer_player and archer_enemy Reduce their speed by 20%
User prompt
After every 2 soldier_enemy uses, the enemy uses 1 archer_enemy
User prompt
Use both enemy units equally
/**** * Plugins ****/ var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Arrow class for castle arrow shooting var Arrow = Container.expand(function () { var self = Container.call(this); // Increase arrow speed for longer distance self.speed = 40; // px per frame (was 32) self.damage = 2 + Math.floor(Math.random() * 3); // 2-4 damage self.target = null; self.team = null; self.destroyed = false; self.asset = null; self.lastX = 0; self.lastY = 0; // Initialize arrow self.init = function (x, y, target, damage, team) { self.x = x; self.y = y; self.target = target; // Arrow damage is randomized 2-4, ignore passed damage param for castle arrows self.damage = 2 + Math.floor(Math.random() * 3); self.team = team; // Remove previous asset if any if (self.asset) { self.removeChild(self.asset); } // Use a visible arrow using a rectangle shape since centerCircle is removed self.asset = self.attachAsset('arrow_shape', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 0.3, tint: team === 'player' ? 0x00aaff : 0xffaa00 // more visible blue/orange }); }; // Update arrow position and check for hit self.update = function () { self.lastX = self.x; self.lastY = self.y; if (!self.target || self.target.destroyed || self.destroyed) { self.destroyed = true; self.destroy(); return; } // Move towards target var dx = self.target.x - self.x; var dy = self.target.y - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 1) dist = 1; var vx = dx / dist * self.speed; var vy = dy / dist * self.speed; self.x += vx; self.y += vy; // Rotate arrow to face target self.asset.rotation = Math.atan2(dy, dx); // Check for collision with target (simple distance check) if (dist < 60) { // Hit! if (typeof self.target.health === "number") { self.target.health -= self.damage; // If the target is a soldier and its health drops to 0 or below, destroy it and remove from array if (self.target.health <= 0 && typeof self.target.team === "string") { self.target.destroyed = true; self.target.destroy(); // Remove from correct array if (self.target.team === "enemy" && typeof enemySoldiers !== "undefined") { for (var i = 0; i < enemySoldiers.length; i++) { if (enemySoldiers[i] === self.target) { enemySoldiers.splice(i, 1); break; } } } else if (self.target.team === "player" && typeof playerSoldiers !== "undefined") { for (var i = 0; i < playerSoldiers.length; i++) { if (playerSoldiers[i] === self.target) { playerSoldiers.splice(i, 1); break; } } } } } self.destroyed = true; self.destroy(); } // Remove if out of bounds (double the distance for longer arrows) if (self.x < -600 || self.x > 3200 || self.y < -600 || self.y > 4000) { self.destroyed = true; self.destroy(); } }; return self; }); // Castle class for player and enemy castles var Castle = Container.expand(function () { var self = Container.call(this); // Properties self.team = null; self.health = CASTLE_HEALTH_INIT; self.hasUpgrade = false; self.attack = 0; self.arrowCooldown = 0; self.arrowCooldownMax = 60; // frames between shots self.attackRadius = 500; // px, for arrow shooting self.asset = null; // Initialize castle self.init = function (team, x, y) { self.team = team; self.x = x; self.y = y; self.health = CASTLE_HEALTH_INIT; self.hasUpgrade = false; self.attack = 0; self.arrowCooldown = 0; // Remove previous asset if any if (self.asset) { self.removeChild(self.asset); } // Add correct asset if (team === 'player') { self.asset = self.attachAsset('castle_player', { anchorX: 0.5, anchorY: 0.5 }); } else { self.asset = self.attachAsset('castle_enemy', { anchorX: 0.5, anchorY: 0.5 }); } }; // Upgrade castle self.upgrade = function () { self.hasUpgrade = true; self.health = 1500; self.attack = 1 + Math.floor(Math.random() * 3); // 1-3 self.arrowCooldown = 0; }; // Update castle (shoot arrows if upgraded) self.update = function () { if (self.hasUpgrade && self.health > 0) { // Only shoot at enemy soldiers in range var targets = []; if (self.team === 'player') { for (var i = 0; i < enemySoldiers.length; i++) { var e = enemySoldiers[i]; var dx = e.x - self.x; var dy = e.y - self.y; if (dx * dx + dy * dy <= self.attackRadius * self.attackRadius) { targets.push(e); } } } else { for (var i = 0; i < playerSoldiers.length; i++) { var e = playerSoldiers[i]; var dx = e.x - self.x; var dy = e.y - self.y; if (dx * dx + dy * dy <= self.attackRadius * self.attackRadius) { targets.push(e); } } } // Shoot at first target if cooldown is ready if (targets.length > 0 && self.arrowCooldown <= 0) { var target = targets[0]; var arrow = new Arrow(); arrow.init(self.x, self.y, target, self.attack, self.team); arrows.push(arrow); game.addChild(arrow); self.arrowCooldown = self.arrowCooldownMax; } if (self.arrowCooldown > 0) self.arrowCooldown--; } }; return self; }); // Soldier class for both player and enemy soldiers var Soldier = Container.expand(function () { var self = Container.call(this); self.team = null; self.health = 100; self.attack = 10; self.speed = SOLDIER_SPEED; self.inCombat = false; self.asset = null; self.lastX = 0; self.lastY = 0; // Initialize soldier self.init = function (team, health, attack) { self.team = team; self.health = health; self.attack = attack; self.inCombat = false; // Remove previous asset if any if (self.asset) { self.removeChild(self.asset); } // Add correct asset if (team === 'player') { self.asset = self.attachAsset('soldier_player', { anchorX: 0.5, anchorY: 0.5 }); } else { self.asset = self.attachAsset('soldier_enemy', { anchorX: 0.5, anchorY: 0.5 }); } }; // Update soldier position (move forward if not in combat) self.update = function () { self.lastX = self.x; self.lastY = self.y; if (!self.inCombat) { if (self.team === 'player') { self.x += self.speed; } else { self.x -= self.speed; } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xBFFF00 }); /**** * Game Code ****/ // --- Add background image --- var background = LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0, width: GAME_W, height: GAME_H }); game.addChild(background); // --- Game constants --- // Player castle (blue) // Enemy castle (red) // Player soldier (green) // Enemy soldier (orange) var GAME_W = 2048, GAME_H = 2732; var CASTLE_OFFSET_X = 120, CASTLE_OFFSET_Y = GAME_H - 520; // moved up by 200px var CASTLE_HEALTH_INIT = 1000; var GOLD_INIT = 200; var GOLD_PER_TICK = 5; var GOLD_TICK_MS = 200; var SOLDIER_COST = 100; var SOLDIER_HEALTH_MIN = 80, SOLDIER_HEALTH_MAX = 160; var SOLDIER_ATTACK_MIN = 20, SOLDIER_ATTACK_MAX = 50; var SOLDIER_SPEED = 14 / 5; // px per frame (slowed down by 5x) // --- Difficulty selection --- var difficulty = null; var ENEMY_SOLDIER_COST = 100; // default, will be set by difficulty // Show difficulty selection overlay var diffOverlay = new Container(); diffOverlay.zIndex = 10000; // ensure on top diffOverlay.width = GAME_W; diffOverlay.height = GAME_H; // Use a Text2 as a fake overlay background (solid block) since centerCircle is removed var overlayBg = new Text2(" ", { size: 10, fill: 0x000000 }); overlayBg.width = GAME_W; overlayBg.height = GAME_H; overlayBg.alpha = 0.7; overlayBg.x = 0; overlayBg.y = 0; diffOverlay.addChild(overlayBg); // Difficulty title with black background var diffTitleBg = new Text2(" ", { size: 10, fill: 0x000000 }); diffTitleBg.width = 900; diffTitleBg.height = 160; diffTitleBg.alpha = 0.95; diffTitleBg.anchor.set(0.5, 0.5); diffTitleBg.x = GAME_W / 2; diffTitleBg.y = GAME_H / 2 - 300; diffOverlay.addChild(diffTitleBg); var diffTitle = new Text2("Select Difficulty", { size: 120, fill: "#fff" }); diffTitle.anchor.set(0.5, 0.5); diffTitle.x = GAME_W / 2; diffTitle.y = GAME_H / 2 - 300; diffOverlay.addChild(diffTitle); // Easy button with black background var btnEasyBg = new Text2(" ", { size: 10, fill: 0x000000 }); btnEasyBg.width = 600; btnEasyBg.height = 120; btnEasyBg.alpha = 0.95; btnEasyBg.anchor.set(0.5, 0.5); btnEasyBg.x = GAME_W / 2; btnEasyBg.y = GAME_H / 2 - 80; diffOverlay.addChild(btnEasyBg); var btnEasy = new Text2("Easy", { size: 100, fill: 0x00FF00 }); btnEasy.anchor.set(0.5, 0.5); btnEasy.x = GAME_W / 2; btnEasy.y = GAME_H / 2 - 80; diffOverlay.addChild(btnEasy); // Normal button with black background var btnNormalBg = new Text2(" ", { size: 10, fill: 0x000000 }); btnNormalBg.width = 600; btnNormalBg.height = 120; btnNormalBg.alpha = 0.95; btnNormalBg.anchor.set(0.5, 0.5); btnNormalBg.x = GAME_W / 2; btnNormalBg.y = GAME_H / 2 + 80; diffOverlay.addChild(btnNormalBg); var btnNormal = new Text2("Normal", { size: 100, fill: 0xFFFF00 }); btnNormal.anchor.set(0.5, 0.5); btnNormal.x = GAME_W / 2; btnNormal.y = GAME_H / 2 + 80; diffOverlay.addChild(btnNormal); // Hard button with black background var btnHardBg = new Text2(" ", { size: 10, fill: 0x000000 }); btnHardBg.width = 600; btnHardBg.height = 120; btnHardBg.alpha = 0.95; btnHardBg.anchor.set(0.5, 0.5); btnHardBg.x = GAME_W / 2; btnHardBg.y = GAME_H / 2 + 240; diffOverlay.addChild(btnHardBg); var btnHard = new Text2("Hard", { size: 100, fill: 0xFF0000 }); btnHard.anchor.set(0.5, 0.5); btnHard.x = GAME_W / 2; btnHard.y = GAME_H / 2 + 240; diffOverlay.addChild(btnHard); game.addChild(diffOverlay); // Disable game input until difficulty is chosen var gameInputEnabled = false; // Helper to start game with selected difficulty function selectDifficulty(level) { difficulty = level; if (difficulty === "easy") { ENEMY_SOLDIER_COST = SOLDIER_COST; // same as player } else if (difficulty === "normal") { ENEMY_SOLDIER_COST = Math.floor(SOLDIER_COST * 0.9); // 0.9 of player } else if (difficulty === "hard") { ENEMY_SOLDIER_COST = Math.floor(SOLDIER_COST * 0.7); // 0.7 of player } gameInputEnabled = true; diffOverlay.destroy(); // Show solder button in the middle section (archerBtn will appear after upgrade) archerBtn.visible = false; solderBtn.visible = true; } // Add touch/click handlers for buttons btnEasy.down = function (x, y, obj) { selectDifficulty("easy"); }; btnNormal.down = function (x, y, obj) { selectDifficulty("normal"); }; btnHard.down = function (x, y, obj) { selectDifficulty("hard"); }; // --- State variables --- // (removed, handled by castlePlayer.health and castleEnemy.health) var playerGold = GOLD_INIT; var enemyGold = GOLD_INIT; var playerSoldiers = []; var enemySoldiers = []; // --- Castles --- var castlePlayer = new Castle(); castlePlayer.init('player', CASTLE_OFFSET_X, CASTLE_OFFSET_Y); game.addChild(castlePlayer); var castleEnemy = new Castle(); castleEnemy.init('enemy', GAME_W - CASTLE_OFFSET_X, CASTLE_OFFSET_Y); game.addChild(castleEnemy); // --- Enemy castle health display above castle --- var castleEnemyHealthTxt = new Text2(castleEnemy.health + '', { size: 60, fill: '#fff' }); castleEnemyHealthTxt.anchor.set(0.5, 1.2); castleEnemyHealthTxt.x = castleEnemy.x; castleEnemyHealthTxt.y = castleEnemy.y - 260; // above the castle game.addChild(castleEnemyHealthTxt); // --- Player castle unit cost labels above castle --- var soldierCostTxt = new Text2("soldier 100 gold", { size: 54, fill: "#000" }); soldierCostTxt.anchor.set(0.5, 1.2); soldierCostTxt.x = castlePlayer.x; soldierCostTxt.y = castlePlayer.y - 260; game.addChild(soldierCostTxt); var cavalryCostTxt = new Text2("cavalry 120 gold", { size: 54, fill: "#000" }); cavalryCostTxt.anchor.set(0.5, 1.02); cavalryCostTxt.x = castlePlayer.x; cavalryCostTxt.y = castlePlayer.y - 180; game.addChild(cavalryCostTxt); // --- Player castle upgrade cost label under player castle --- var playerCastleUpgradeTxt = new Text2("YOU NEED 350 GOLD\nTO UPGRADE.", { size: 54, fill: "#000" }); playerCastleUpgradeTxt.anchor.set(0.5, -0.2); // anchor above the text baseline playerCastleUpgradeTxt.x = castlePlayer.x + 180; playerCastleUpgradeTxt.y = castlePlayer.y + 320; // under the castle game.addChild(playerCastleUpgradeTxt); // --- Left side: archer_button and solder_button side by side, visible on screen --- var leftButtonsY = GAME_H / 2 + 100; var leftButtonSpacing = 40; var leftButtonStartX = 120 + 75; // 120px margin + half button width (150/2) // Archer button (leftmost) var archerBtn = LK.getAsset('archer_button', { anchorX: 0.5, anchorY: 0.5, x: leftButtonStartX, y: leftButtonsY }); archerBtn.visible = false; game.addChild(archerBtn); // Solder button (right of archer) var solderBtn = LK.getAsset('solder_button', { anchorX: 0.5, anchorY: 0.5, x: leftButtonStartX + 150 + leftButtonSpacing, // 150 is button width y: leftButtonsY }); solderBtn.visible = false; game.addChild(solderBtn); // --- GUI: Health and Gold displays --- var playerHealthTxt = new Text2('1000', { size: 70, fill: '#fff' }); playerHealthTxt.anchor.set(0, 0); LK.gui.top.addChild(playerHealthTxt); // Player LIFE label var playerLifeLabel = new Text2('LIFE', { size: 38, fill: "#000" }); playerLifeLabel.anchor.set(0, 0); LK.gui.top.addChild(playerLifeLabel); var playerGoldTxt = new Text2('200', { size: 60, fill: '#ffe600' }); playerGoldTxt.anchor.set(0, 0); LK.gui.top.addChild(playerGoldTxt); // Add soldier/cavalry cost labels to the left of the tan score var guiSoldierCostTxt = new Text2("soldier 100 gold", { size: 38, fill: "#000" }); guiSoldierCostTxt.anchor.set(1, 0); LK.gui.top.addChild(guiSoldierCostTxt); var guiCavalryCostTxt = new Text2("cavalry 120 gold", { size: 38, fill: "#000" }); guiCavalryCostTxt.anchor.set(1, 0); LK.gui.top.addChild(guiCavalryCostTxt); // Player GOLD label var playerGoldLabel = new Text2('GOLD', { size: 38, fill: "#000" }); playerGoldLabel.anchor.set(0, 0); LK.gui.top.addChild(playerGoldLabel); var enemyHealthTxt = new Text2('1000', { size: 70, fill: '#fff' }); enemyHealthTxt.anchor.set(1, 0); LK.gui.top.addChild(enemyHealthTxt); // Enemy LIFE label var enemyLifeLabel = new Text2('LIFE', { size: 38, fill: "#000" }); enemyLifeLabel.anchor.set(1, 0); LK.gui.top.addChild(enemyLifeLabel); var enemyGoldTxt = new Text2('200', { size: 60, fill: '#ffe600' }); enemyGoldTxt.anchor.set(1, 0); LK.gui.top.addChild(enemyGoldTxt); // Enemy GOLD label var enemyGoldLabel = new Text2('GOLD', { size: 38, fill: "#000" }); enemyGoldLabel.anchor.set(1, 0); LK.gui.top.addChild(enemyGoldLabel); // --- Win Counter (Rounds Won) --- // Use storage plugin for persistence var roundsWon = storage.roundsWon || 0; var roundsWonTxt = new Text2('Rounds Won: ' + roundsWon, { size: 60, fill: '#00ff00' }); roundsWonTxt.anchor.set(1, 0); LK.gui.top.addChild(roundsWonTxt); roundsWonTxt.x = LK.gui.width - 40; roundsWonTxt.y = 220; // Position GUI elements playerHealthTxt.x = 120; playerHealthTxt.y = 40; playerLifeLabel.x = playerHealthTxt.x + playerHealthTxt.width + 18; playerLifeLabel.y = playerHealthTxt.y + 10; playerGoldTxt.x = 120; playerGoldTxt.y = 120; playerGoldLabel.x = playerGoldTxt.x + playerGoldTxt.width + 18; playerGoldLabel.y = playerGoldTxt.y + 8; // Position soldier/cavalry cost labels to the left of the tan score guiSoldierCostTxt.x = playerGoldTxt.x - 30; guiSoldierCostTxt.y = playerGoldTxt.y - 8; guiCavalryCostTxt.x = playerGoldTxt.x - 30; guiCavalryCostTxt.y = playerGoldTxt.y + 38; enemyHealthTxt.x = LK.gui.width - 120; enemyHealthTxt.y = 40; enemyLifeLabel.x = enemyHealthTxt.x - enemyHealthTxt.width - 18; enemyLifeLabel.y = enemyHealthTxt.y + 10; enemyGoldTxt.x = LK.gui.width - 120; enemyGoldTxt.y = 120; enemyGoldLabel.x = enemyGoldTxt.x - enemyGoldTxt.width - 18; enemyGoldLabel.y = enemyGoldTxt.y + 8; // --- Gold income timer --- var goldTimer = LK.setInterval(function () { // Only increase gold if difficulty has been chosen if (!gameInputEnabled) return; playerGold += GOLD_PER_TICK; enemyGold += GOLD_PER_TICK; updateGui(); }, GOLD_TICK_MS); // --- GUI update function --- function updateGui() { playerHealthTxt.setText(castlePlayer.health); playerLifeLabel.x = playerHealthTxt.x + playerHealthTxt.width + 18; playerLifeLabel.y = playerHealthTxt.y + 10; playerGoldTxt.setText(playerGold); playerGoldLabel.x = playerGoldTxt.x + playerGoldTxt.width + 18; playerGoldLabel.y = playerGoldTxt.y + 8; enemyHealthTxt.setText(castleEnemy.health); enemyLifeLabel.x = enemyHealthTxt.x - enemyHealthTxt.width - 18; enemyLifeLabel.y = enemyHealthTxt.y + 10; enemyGoldTxt.setText(enemyGold); enemyGoldLabel.x = enemyGoldTxt.x - enemyGoldTxt.width - 18; enemyGoldLabel.y = enemyGoldTxt.y + 8; // Update enemy castle health text and position castleEnemyHealthTxt.setText(castleEnemy.health); castleEnemyHealthTxt.x = castleEnemy.x; castleEnemyHealthTxt.y = castleEnemy.y - 260; } // --- Deploy soldier function --- function deploySoldier(team) { // Block deployment if difficulty not chosen if (!gameInputEnabled) return false; var gold = team === 'player' ? playerGold : enemyGold; var cost = team === 'player' ? SOLDIER_COST : ENEMY_SOLDIER_COST; if (gold < cost) return false; // Deduct gold if (team === 'player') playerGold -= SOLDIER_COST;else enemyGold -= ENEMY_SOLDIER_COST; // Fixed health and random attack var health = 25; var attack = 5 + Math.floor(Math.random() * 6); // 5-10 inclusive // Create soldier var s = new Soldier(); s.init(team, health, attack); s.speed = SOLDIER_SPEED; s.inCombat = false; // Position s.y = CASTLE_OFFSET_Y + 120; // Move soldiers' exit position down by 120px if (team === 'player') { s.x = castlePlayer.x + 120; playerSoldiers.push(s); } else { s.x = castleEnemy.x - 120; enemySoldiers.push(s); } game.addChild(s); return true; } // --- Player tap to upgrade castle only (soldier deploy moved to solderBtn.down) --- game.down = function (x, y, obj) { // Block input until difficulty is chosen if (!gameInputEnabled) return; // Check if player clicked on their castle for upgrade var dx = x - castlePlayer.x; var dy = y - castlePlayer.y; if (dx * dx + dy * dy < 250 * 250 && !castlePlayer.hasUpgrade && playerGold >= 350) { playerGold -= 350; castlePlayer.upgrade(); updateGui(); // Show archerBtn after upgrade archerBtn.visible = true; // Remove the upgrade text after rising the castle if (playerCastleUpgradeTxt && typeof playerCastleUpgradeTxt.destroy === "function") { playerCastleUpgradeTxt.destroy(); playerCastleUpgradeTxt = null; } return; } // (Removed: deploySoldier on screen tap) }; // --- Deploy soldier when solderBtn is pressed --- solderBtn.down = function (x, y, obj) { if (!gameInputEnabled) return; if (playerGold >= SOLDIER_COST) { deploySoldier('player'); updateGui(); } }; // --- Deploy archer_player when archerBtn is pressed (uses archer_player asset, cost 10 gold) --- archerBtn.down = function (x, y, obj) { if (!gameInputEnabled) return; if (playerGold >= 120) { playerGold -= 120; // Create a new Soldier but use archer_player asset var s = new Soldier(); // Set archer_player health to be twice that of soldier_player var baseSoldierHealth = 25; s.init('player', baseSoldierHealth * 2, 5 + Math.floor(Math.random() * 6)); // health 50, attack 5-10 s.speed = SOLDIER_SPEED * 0.8; s.inCombat = false; // Remove previous asset and attach archer_player asset if (s.asset) { s.removeChild(s.asset); } s.asset = s.attachAsset('archer_player', { anchorX: 0.5, anchorY: 0.5 }); // Position s.y = CASTLE_OFFSET_Y + 120; s.x = castlePlayer.x + 120; playerSoldiers.push(s); game.addChild(s); updateGui(); } }; // --- Enemy AI: deploy soldier automatically if enough gold --- // Track enemy soldier deployments for 2:1 soldier:archer ratio var enemySoldierDeployCount = 0; var enemyNextUnit = 'soldier'; // always start with soldier var enemyTotalSoldierDeployed = 0; var enemyUpgradeGoldReserved = 200; var enemyDeployTimer = LK.setInterval(function () { // Block AI until difficulty is chosen if (!gameInputEnabled) return; // If not upgraded, reserve 200 gold for upgrade after 10 soldiers if (!castleEnemy.hasUpgrade) { // In hard mode, upgrade for free after 10 soldiers if (difficulty === "hard") { if (enemyTotalSoldierDeployed >= 10) { castleEnemy.upgrade(); updateGui(); return; } } else { // Only upgrade after 10 soldier_enemy deployed and enough gold (350 - 200 = 150 must be available for upgrade) if (enemyTotalSoldierDeployed >= 10 && enemyGold >= 350 - enemyUpgradeGoldReserved) { enemyGold -= 350 - enemyUpgradeGoldReserved; castleEnemy.upgrade(); updateGui(); return; } } } // If not upgraded and haven't deployed 10 soldiers, only deploy if enough gold and after reserving 200 for upgrade if (!castleEnemy.hasUpgrade && enemyTotalSoldierDeployed < 10) { if (enemyNextUnit === 'soldier' && enemyGold >= ENEMY_SOLDIER_COST + enemyUpgradeGoldReserved) { if (deploySoldier('enemy')) { updateGui(); enemySoldierDeployCount++; enemyTotalSoldierDeployed++; // After 2 soldiers, next must be archer (if possible) if (enemySoldierDeployCount >= 2) { enemyNextUnit = 'soldier'; // No archers before upgrade enemySoldierDeployCount = 0; } } } // Do not deploy archers before upgrade return; } // After upgrade, normal logic: after every 2 soldiers, deploy 1 archer if (enemyNextUnit === 'soldier' && enemyGold >= ENEMY_SOLDIER_COST) { if (deploySoldier('enemy')) { updateGui(); enemySoldierDeployCount++; enemyTotalSoldierDeployed++; // After 2 soldiers, next must be archer (if possible) if (enemySoldierDeployCount >= 2 && castleEnemy.hasUpgrade) { enemyNextUnit = 'archer'; } else { enemyNextUnit = 'soldier'; } } } else if (enemyNextUnit === 'archer' && castleEnemy.hasUpgrade && enemyGold >= 120) { // Deploy archer_enemy enemyGold -= 120; var s = new Soldier(); var baseSoldierHealth = 25; s.init('enemy', baseSoldierHealth * 2, 5 + Math.floor(Math.random() * 6)); // health 50, attack 5-10 s.speed = SOLDIER_SPEED * 0.8; s.inCombat = false; if (s.asset) { s.removeChild(s.asset); } s.asset = s.attachAsset('archer_enemy', { anchorX: 0.5, anchorY: 0.5 }); s.y = CASTLE_OFFSET_Y + 120; s.x = castleEnemy.x - 120; enemySoldiers.push(s); game.addChild(s); updateGui(); // Reset soldier deploy count and go back to soldier enemySoldierDeployCount = 0; enemyNextUnit = 'soldier'; } }, 600); // --- Arrows array --- var arrows = []; // --- Main update loop --- game.update = function () { // --- Update castles (health, arrows) --- castlePlayer.update(); castleEnemy.update(); // --- Update all soldiers --- // 1. Move soldiers forward if not in combat // 2. Check for combat with opposing soldiers // 3. If at enemy castle, attack castle // --- Player soldiers --- for (var i = playerSoldiers.length - 1; i >= 0; i--) { var s = playerSoldiers[i]; s.inCombat = false; // Check for enemy soldier in range var engaged = false; for (var j = 0; j < enemySoldiers.length; j++) { var e = enemySoldiers[j]; // If close enough (overlap) if (Math.abs(s.x - e.x) < 80) { // Engage in combat s.inCombat = true; e.inCombat = true; // Both attack each other if (LK.ticks % 12 === 0) { // Attack every 12 frames (~5 times/sec) e.health -= s.attack; s.health -= e.attack; } // Remove dead soldiers if (e.health <= 0) { e.destroy(); enemySoldiers.splice(j, 1); j--; // Award 10 gold to player for killing enemy soldier playerGold += 10; updateGui(); } if (s.health <= 0) { s.destroy(); playerSoldiers.splice(i, 1); i--; // Award 10 gold to enemy for killing player soldier enemyGold += 10; updateGui(); engaged = true; break; } engaged = true; break; } } if (engaged) continue; // If not in combat, check if at enemy castle if (Math.abs(s.x - castleEnemy.x) < 120) { s.inCombat = true; if (LK.ticks % 12 === 0) { castleEnemy.health -= s.attack; if (castleEnemy.health < 0) castleEnemy.health = 0; updateGui(); } // Remove soldier if castle destroyed if (castleEnemy.health <= 0) { s.destroy(); playerSoldiers.splice(i, 1); i--; } } } // --- Enemy soldiers --- for (var i = enemySoldiers.length - 1; i >= 0; i--) { var s = enemySoldiers[i]; s.inCombat = false; // Check for player soldier in range var engaged = false; for (var j = 0; j < playerSoldiers.length; j++) { var e = playerSoldiers[j]; if (Math.abs(s.x - e.x) < 80) { s.inCombat = true; e.inCombat = true; if (LK.ticks % 12 === 0) { e.health -= s.attack; s.health -= e.attack; } if (e.health <= 0) { e.destroy(); playerSoldiers.splice(j, 1); j--; // Award 10 gold to enemy for killing player soldier enemyGold += 10; updateGui(); } if (s.health <= 0) { s.destroy(); enemySoldiers.splice(i, 1); i--; // Award 10 gold to player for killing enemy soldier playerGold += 10; updateGui(); engaged = true; break; } engaged = true; break; } } if (engaged) continue; // If not in combat, check if at player castle if (Math.abs(s.x - castlePlayer.x) < 120) { s.inCombat = true; if (LK.ticks % 12 === 0) { castlePlayer.health -= s.attack; if (castlePlayer.health < 0) castlePlayer.health = 0; updateGui(); } if (castlePlayer.health <= 0) { s.destroy(); enemySoldiers.splice(i, 1); i--; } } } // --- Move soldiers --- for (var i = 0; i < playerSoldiers.length; i++) { playerSoldiers[i].update(); } for (var i = 0; i < enemySoldiers.length; i++) { enemySoldiers[i].update(); } // --- Update arrows --- for (var i = arrows.length - 1; i >= 0; i--) { var a = arrows[i]; a.update(); if (a.destroyed) { arrows.splice(i, 1); } } // --- Check win/lose --- if (castlePlayer.health <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } if (castleEnemy.health <= 0) { // Increase and persist rounds won roundsWon = (storage.roundsWon || 0) + 1; storage.roundsWon = roundsWon; roundsWonTxt.setText('Rounds Won: ' + roundsWon); LK.effects.flashScreen(0x00ff00, 1000); LK.showYouWin(); return; } }; // --- Clean up timers on game over --- game.destroy = function () { LK.clearInterval(goldTimer); LK.clearInterval(enemyDeployTimer); };
===================================================================
--- original.js
+++ change.js
@@ -486,8 +486,21 @@
fill: '#ffe600'
});
playerGoldTxt.anchor.set(0, 0);
LK.gui.top.addChild(playerGoldTxt);
+// Add soldier/cavalry cost labels to the left of the tan score
+var guiSoldierCostTxt = new Text2("soldier 100 gold", {
+ size: 38,
+ fill: "#000"
+});
+guiSoldierCostTxt.anchor.set(1, 0);
+LK.gui.top.addChild(guiSoldierCostTxt);
+var guiCavalryCostTxt = new Text2("cavalry 120 gold", {
+ size: 38,
+ fill: "#000"
+});
+guiCavalryCostTxt.anchor.set(1, 0);
+LK.gui.top.addChild(guiCavalryCostTxt);
// Player GOLD label
var playerGoldLabel = new Text2('GOLD', {
size: 38,
fill: "#000"
@@ -539,8 +552,13 @@
playerGoldTxt.x = 120;
playerGoldTxt.y = 120;
playerGoldLabel.x = playerGoldTxt.x + playerGoldTxt.width + 18;
playerGoldLabel.y = playerGoldTxt.y + 8;
+// Position soldier/cavalry cost labels to the left of the tan score
+guiSoldierCostTxt.x = playerGoldTxt.x - 30;
+guiSoldierCostTxt.y = playerGoldTxt.y - 8;
+guiCavalryCostTxt.x = playerGoldTxt.x - 30;
+guiCavalryCostTxt.y = playerGoldTxt.y + 38;
enemyHealthTxt.x = LK.gui.width - 120;
enemyHealthTxt.y = 40;
enemyLifeLabel.x = enemyHealthTxt.x - enemyHealthTxt.width - 18;
enemyLifeLabel.y = enemyHealthTxt.y + 10;
ottoman castle. In-Game asset. 2d. High contrast. No shadows. pixel art
roma knight. In-Game asset. 2d. High contrast. No shadows
Ottoman Janissary. In-Game asset. 2d. High contrast. No shadows
sword. In-Game asset. 2d. High contrast. No shadows
Ottoman camel warrior. In-Game asset. 2d. High contrast. No shadows. pixel art
Roman cavalry. In-Game asset. 2d. High contrast. No shadows
camel face. In-Game asset. 2d. High contrast. No shadows. pixel art
wall icon game. In-Game asset. 2d. High contrast. No shadows
RED CRESCENT ICON. In-Game asset. 2d. High contrast. No shadows
HEALING TENT OTTOMAN. In-Game asset. 2d. High contrast. No shadows