User prompt
for each level my enemy health and attack values are as follows - Level 1 Health: 20 - 100 random Attack: 1 - 20 random Attack Speed: 1 - 5 random 🔹 Level 2 Health: 50 - 150 random Attack: 5 - 25 random Attack Speed: 2 - 6 random 🔹 Level 3 Health: 80 - 200 random Attack: 10 - 30 random Attack Speed: 3 - 7 random 🔹 Level 4 Health: 110 - 250 random Attack: 15 - 35 random Attack Speed: 4 - 8 random 🔹 Level 5 Health: 150 - 300 random Attack: 20 - 40 random Attack Speed: 5 - 9 random 🔹 Level 6 Health: 200 - 360 random Attack: 25 - 45 random Attack Speed: 6 - 10 random 🔹 Level 7 Health: 250 - 420 random Attack: 30 - 50 random Attack Speed: 7 - 11 random 🔹 Level 8 Health: 300 - 480 random Attack: 35 - 55 random Attack Speed: 8 - 12 random 🔹 Level 9 Health: 350 - 540 random Attack: 40 - 60 random Attack Speed: 9 - 13 random 🔹 Level 10 Health: 400 - 600 random Attack: 45 - 70 random Attack Speed: 10 - 15 random /// set the enemy statistics like this I will get enemies like this from level 1 to level 10
User prompt
The enemy will be on the far right of the screen.
User prompt
The buttons are not visible, make sure you installed it in the correct places
User prompt
Add the spawnBtn and upgradeBtn buttons to the locations I mentioned.
User prompt
the main character will appear on the left side of the screen, there will be a button in the middle bottom part, when we click on that button, an enemy will appear in front of him "spawnBtn", gold will drop from the enemy, there will be a button in the middle top part and that button will develop the character and increase the level "upgradeBtn", our gold amount will be written in the upper right part
Code edit (1 edits merged)
Please save this source code
User prompt
Gold Drop Hero
Initial prompt
The main character will appear on the left side of the screen, there will be a button in the middle bottom part, when we click on that button, an enemy will come in front of him, gold will drop from the enemy, there will be a button in the middle top part and that button will develop the character, increase the level and our gold amount will be written in the upper right part
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGfx = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.hp = 1; self.x = 600; self.y = 2732 / 2; self.isAlive = true; // Animate enemy in self.spawnAnim = function () { self.scaleX = 0.5; self.scaleY = 0.5; tween(self, { scaleX: 1, scaleY: 1 }, { duration: 180, easing: tween.bounceOut }); }; // Animate enemy defeat self.defeatAnim = function (onFinish) { tween(self, { alpha: 0, scaleX: 1.3, scaleY: 1.3 }, { duration: 180, easing: tween.easeIn, onFinish: onFinish }); }; return self; }); // Gold class var Gold = Container.expand(function () { var self = Container.call(this); var goldGfx = self.attachAsset('gold', { anchorX: 0.5, anchorY: 0.5 }); self.x = 600; self.y = 2732 / 2; // Animate gold drop self.dropAnim = function (targetX, targetY, onFinish) { tween(self, { y: targetY }, { duration: 350, easing: tween.bounceOut, onFinish: onFinish }); }; // Animate gold collect self.collectAnim = function (targetX, targetY, onFinish) { tween(self, { x: targetX, y: targetY, scaleX: 0.3, scaleY: 0.3, alpha: 0 }, { duration: 320, easing: tween.cubicIn, onFinish: onFinish }); }; return self; }); // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGfx = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.level = 1; self.x = 200; self.y = 2732 / 2; // For upgrade animation self.flashUpgrade = function () { tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 120, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 120, easing: tween.easeIn }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222a36 }); /**** * Game Code ****/ // Upgrade Button: orange box // Spawn Enemy Button: green box // Gold: yellow ellipse // Enemy: blue ellipse // Hero: red box, left side // --- Global State --- var hero = new Hero(); game.addChild(hero); var currentEnemy = null; var golds = []; var goldAmount = 0; var heroLevel = 1; // --- GUI Elements --- // Gold display (top right) var goldTxt = new Text2('0', { size: 100, fill: 0xFFE066 }); goldTxt.anchor.set(1, 0); // right, top LK.gui.topRight.addChild(goldTxt); // Upgrade button (top center) var upgradeBtn = LK.getAsset('upgradeBtn', { anchorX: 0.5, anchorY: 0.5 }); // Place upgradeBtn at top center, but not in the top left 100x100 area var upgradeBtnY = 100 + upgradeBtn.height / 2; upgradeBtn.x = 2048 / 2; upgradeBtn.y = upgradeBtnY; LK.gui.top.addChild(upgradeBtn); var upgradeTxt = new Text2('Upgrade\nLvl: 1', { size: 60, fill: "#fff" }); upgradeTxt.anchor.set(0.5, 0.5); upgradeTxt.x = upgradeBtn.x; upgradeTxt.y = upgradeBtn.y; LK.gui.top.addChild(upgradeTxt); // Spawn enemy button (bottom center) var spawnBtn = LK.getAsset('spawnBtn', { anchorX: 0.5, anchorY: 0.5 }); // Place spawnBtn at bottom center, above the very bottom edge var spawnBtnY = 2732 - 100 - spawnBtn.height / 2; spawnBtn.x = 2048 / 2; spawnBtn.y = spawnBtnY; LK.gui.bottom.addChild(spawnBtn); var spawnTxt = new Text2('Spawn Enemy', { size: 60, fill: "#fff" }); spawnTxt.anchor.set(0.5, 0.5); spawnTxt.x = spawnBtn.x; spawnTxt.y = spawnBtn.y; LK.gui.bottom.addChild(spawnTxt); // --- Helper Functions --- function updateGoldDisplay() { goldTxt.setText(goldAmount); } function updateUpgradeDisplay() { upgradeTxt.setText('Upgrade\nLvl: ' + heroLevel); } // --- Game Logic --- // Spawn enemy logic function spawnEnemy() { if (currentEnemy && currentEnemy.isAlive) return; // Only one at a time var enemy = new Enemy(); // Place enemy in front of hero, vertically aligned enemy.x = hero.x + 320; enemy.y = hero.y; enemy.hp = heroLevel; // Enemy HP scales with hero level enemy.isAlive = true; enemy.spawnAnim(); game.addChild(enemy); currentEnemy = enemy; } // Defeat enemy logic function defeatEnemy() { if (!currentEnemy || !currentEnemy.isAlive) return; currentEnemy.isAlive = false; currentEnemy.defeatAnim(function () { if (currentEnemy) { currentEnemy.destroy(); currentEnemy = null; } }); // Drop gold var gold = new Gold(); gold.x = hero.x + 320; gold.y = hero.y; gold.scaleX = 1; gold.scaleY = 1; gold.alpha = 1; game.addChild(gold); golds.push(gold); // Drop to random y near enemy var dropY = gold.y + (Math.random() * 120 - 60); gold.dropAnim(gold.x, dropY, function () {}); } // Collect gold logic function collectGold(gold) { // Animate to gold display var guiGoldPos = LK.gui.topRight.toLocal(gold.toGlobal({ x: 0, y: 0 })); goldAmount += 1; updateGoldDisplay(); gold.collectAnim(guiGoldPos.x, guiGoldPos.y, function () { gold.destroy(); }); } // Upgrade logic function upgradeHero() { var upgradeCost = heroLevel * 5; if (goldAmount < upgradeCost) { // Flash gold text red tween(goldTxt, { tint: 0xff4444 }, { duration: 120, onFinish: function onFinish() { tween(goldTxt, { tint: 0xFFE066 }, { duration: 120 }); } }); return; } goldAmount -= upgradeCost; heroLevel += 1; hero.level = heroLevel; updateGoldDisplay(); updateUpgradeDisplay(); hero.flashUpgrade(); } // --- Event Handlers --- // Spawn button tap spawnBtn.down = function (x, y, obj) { spawnEnemy(); }; // Enemy tap (defeat) function onEnemyDown(x, y, obj) { if (!currentEnemy || !currentEnemy.isAlive) return; currentEnemy.hp -= 1; // Flash enemy tween(currentEnemy, { tint: 0xffffff }, { duration: 60, onFinish: function onFinish() { tween(currentEnemy, { tint: 0x2a6bde }, { duration: 60 }); } }); if (currentEnemy.hp <= 0) { defeatEnemy(); } } // Gold tap (collect) function onGoldDown(x, y, obj) { for (var i = golds.length - 1; i >= 0; i--) { var gold = golds[i]; if (gold && gold.containsPoint && gold.containsPoint({ x: x, y: y })) { collectGold(gold); golds.splice(i, 1); break; } } } // Upgrade button tap upgradeBtn.down = function (x, y, obj) { upgradeHero(); }; // --- Attach event handlers to game --- game.down = function (x, y, obj) { // Check if tap is on enemy if (currentEnemy && currentEnemy.isAlive && currentEnemy.containsPoint && currentEnemy.containsPoint({ x: x, y: y })) { onEnemyDown(x, y, obj); return; } // Check if tap is on any gold for (var i = golds.length - 1; i >= 0; i--) { var gold = golds[i]; if (gold && gold.containsPoint && gold.containsPoint({ x: x, y: y })) { collectGold(gold); golds.splice(i, 1); return; } } // (Buttons handled by their own .down) }; // --- Game update loop --- game.update = function () { // Remove golds that are invisible for (var i = golds.length - 1; i >= 0; i--) { var gold = golds[i]; if (gold.alpha <= 0.01) { gold.destroy(); golds.splice(i, 1); } } // Keep hero vertically centered hero.y = 2732 / 2; // Keep enemy vertically centered if alive if (currentEnemy && currentEnemy.isAlive) { currentEnemy.y = hero.y; } }; // --- Initial UI state --- updateGoldDisplay(); updateUpgradeDisplay();
===================================================================
--- original.js
+++ change.js
@@ -144,8 +144,9 @@
var upgradeBtn = LK.getAsset('upgradeBtn', {
anchorX: 0.5,
anchorY: 0.5
});
+// Place upgradeBtn at top center, but not in the top left 100x100 area
var upgradeBtnY = 100 + upgradeBtn.height / 2;
upgradeBtn.x = 2048 / 2;
upgradeBtn.y = upgradeBtnY;
LK.gui.top.addChild(upgradeBtn);
@@ -161,8 +162,9 @@
var spawnBtn = LK.getAsset('spawnBtn', {
anchorX: 0.5,
anchorY: 0.5
});
+// Place spawnBtn at bottom center, above the very bottom edge
var spawnBtnY = 2732 - 100 - spawnBtn.height / 2;
spawnBtn.x = 2048 / 2;
spawnBtn.y = spawnBtnY;
LK.gui.bottom.addChild(spawnBtn);