/****
* 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, 2500, 3000, 10000];
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();
}
}
});
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.