User prompt
after you have bought it for 2k then make it cost 2,5 and then 3k and then 10k
User prompt
make the upgrade cost 100 then 200 then 500 then 1000k then 1,5k and then 2k and show on the right side of the upgrade button what it cost each time.
User prompt
write on the side of the upgrade button what it cost to upgrade
Initial prompt
peach clicker game
/**** * Classes ****/ var UpgradeCostDisplay = Container.expand(function () { var self = Container.call(this); self.text = new Text2('', { size: 50, fill: "#ffffff" }); self.text.anchor.set(0.5, 0); self.addChild(self.text); self.updateCost = function (cost) { self.text.setText('Cost: ' + (cost ? cost : 'Max')); }; }); var Peach = Container.expand(function () { var self = Container.call(this); var peachGraphics = self.attachAsset('peach', { anchorX: 0.5, anchorY: 0.5 }); self.interactive = true; self.on('down', function () { game.peachClicked(); }); }); var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.vx = Math.random() * 10 - 5; self.vy = Math.random() * -10 - 5; self.gravity = 0.5; self.move = function () { self.x += self.vx; self.y += self.vy; self.vy += self.gravity; if (self.y > 2732) { self.destroy(); } }; }); var UpgradeButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('upgradeButton', { anchorX: 0.5, anchorY: 0.5 }); self.interactive = true; self.on('down', function () { game.purchaseUpgrade(); }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ game.coins = 0; game.upgradeCosts = [100, 200, 500, 1000, 1500, 2000]; game.currentUpgradeIndex = 0; game.upgradeCost = game.upgradeCosts[game.currentUpgradeIndex]; game.upgradeLevel = 1; game.peach = game.addChild(new Peach()); game.peach.x = 2048 / 2; game.peach.y = 2732 / 2; game.upgradeButton = game.addChild(new UpgradeButton()); game.upgradeButton.x = 2048 / 2; game.upgradeButton.y = 2732 - 200; game.upgradeCostDisplay = game.addChild(new UpgradeCostDisplay()); game.upgradeCostDisplay.x = game.upgradeButton.x + 250; game.upgradeCostDisplay.y = game.upgradeButton.y; game.upgradeCostDisplay.updateCost(game.upgradeCost); game.coinsText = new Text2('Coins: 0', { size: 100, fill: "#ffffff" }); game.coinsText.anchor.set(0.5, 0); LK.gui.top.addChild(game.coinsText); game.peachClicked = function () { var coin = game.addChild(new Coin()); coin.x = game.peach.x; coin.y = game.peach.y; game.coins += game.upgradeLevel; game.updateCoinsText(); }; game.purchaseUpgrade = function () { if (game.coins >= game.upgradeCost) { game.coins -= game.upgradeCost; game.upgradeLevel++; game.currentUpgradeIndex++; if (game.currentUpgradeIndex < game.upgradeCosts.length) { game.upgradeCost = game.upgradeCosts[game.currentUpgradeIndex]; } else { game.upgradeCost = null; // No more upgrades available } game.updateCoinsText(); } }; game.updateCoinsText = function () { game.coinsText.setText('Coins: ' + game.coins); game.upgradeCostDisplay.updateCost(game.upgradeCost); }; LK.on('tick', function () { var children = game.children; for (var i = children.length - 1; i >= 0; i--) { if (children[i] instanceof Coin) { children[i].move(); } } });
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,19 @@
/****
* Classes
****/
+var UpgradeCostDisplay = Container.expand(function () {
+ var self = Container.call(this);
+ self.text = new Text2('', {
+ size: 50,
+ fill: "#ffffff"
+ });
+ self.text.anchor.set(0.5, 0);
+ self.addChild(self.text);
+ self.updateCost = function (cost) {
+ self.text.setText('Cost: ' + (cost ? cost : 'Max'));
+ };
+});
var Peach = Container.expand(function () {
var self = Container.call(this);
var peachGraphics = self.attachAsset('peach', {
anchorX: 0.5,
@@ -52,26 +64,22 @@
/****
* Game Code
****/
game.coins = 0;
-game.upgradeCost = 10;
+game.upgradeCosts = [100, 200, 500, 1000, 1500, 2000];
+game.currentUpgradeIndex = 0;
+game.upgradeCost = game.upgradeCosts[game.currentUpgradeIndex];
game.upgradeLevel = 1;
game.peach = game.addChild(new Peach());
game.peach.x = 2048 / 2;
game.peach.y = 2732 / 2;
game.upgradeButton = game.addChild(new UpgradeButton());
game.upgradeButton.x = 2048 / 2;
game.upgradeButton.y = 2732 - 200;
-// Create and position the upgrade cost text
-var upgradeCostText = new Text2('Cost: ' + game.upgradeCost, {
- size: 50,
- fill: "#ffffff"
-});
-upgradeCostText.anchor.set(0.5, 0);
-upgradeCostText.x = game.upgradeButton.x;
-upgradeCostText.y = game.upgradeButton.y + 250;
-LK.gui.top.addChild(upgradeCostText);
-game.upgradeCostText = upgradeCostText;
+game.upgradeCostDisplay = game.addChild(new UpgradeCostDisplay());
+game.upgradeCostDisplay.x = game.upgradeButton.x + 250;
+game.upgradeCostDisplay.y = game.upgradeButton.y;
+game.upgradeCostDisplay.updateCost(game.upgradeCost);
game.coinsText = new Text2('Coins: 0', {
size: 100,
fill: "#ffffff"
});
@@ -87,18 +95,20 @@
game.purchaseUpgrade = function () {
if (game.coins >= game.upgradeCost) {
game.coins -= game.upgradeCost;
game.upgradeLevel++;
- game.upgradeCost *= 2;
- game.updateCoinsText();
- // Update the upgrade cost text
- if (game.upgradeCostText) {
- game.upgradeCostText.setText('Cost: ' + game.upgradeCost);
+ game.currentUpgradeIndex++;
+ if (game.currentUpgradeIndex < game.upgradeCosts.length) {
+ game.upgradeCost = game.upgradeCosts[game.currentUpgradeIndex];
+ } else {
+ game.upgradeCost = null; // No more upgrades available
}
+ game.updateCoinsText();
}
};
game.updateCoinsText = function () {
game.coinsText.setText('Coins: ' + game.coins);
+ game.upgradeCostDisplay.updateCost(game.upgradeCost);
};
LK.on('tick', function () {
var children = game.children;
for (var i = children.length - 1; i >= 0; i--) {
a peach fruit png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a button png. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
coin png. put it on the right side.
the number 1000. put it on the right side.
peaches. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.