/**** * Classes ****/ // ShopItem class for buying more yogurt var ShopItem = Container.expand(function () { var self = Container.call(this); var shopItemGraphic = self.attachAsset('shopItem', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { if (game.money >= game.yogurtCost) { game.money -= game.yogurtCost; game.yogurtCount += 1; moneyTxt.setText("Money: $" + game.money); yogurtCountTxt.setText("Yogurts: " + game.yogurtCount); } }); }); // Assets will be automatically created based on usage in the code. // Yogurt class var Yogurt = Container.expand(function () { var self = Container.call(this); var yogurtGraphic = self.attachAsset('yogurt', { anchorX: 0.5, anchorY: 0.5 }); self.on('down', function () { game.money += game.earnAmount; moneyTxt.setText("Money: $" + game.money); }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background }); /**** * Game Code ****/ // Game variables game.money = 0; game.earnAmount = 1; game.yogurtCost = 10; game.yogurtCount = 1; // Money display var moneyTxt = new Text2("Money: $" + game.money, { size: 100, fill: "#ffffff", anchorX: 0.5, anchorY: 0 }); LK.gui.top.addChild(moneyTxt); // Yogurt count display var yogurtCountTxt = new Text2("Yogurts: " + game.yogurtCount, { size: 100, fill: "#ffffff", anchorX: 0.5, anchorY: 0 }); LK.gui.topRight.addChild(yogurtCountTxt); // Create a yogurt var yogurt = game.addChild(new Yogurt()); yogurt.x = 2048 / 2; yogurt.y = 2732 / 4; // Position at 1/4th height from the top // Create a shop item to buy more yogurt var shopItem = game.addChild(new ShopItem()); shopItem.x = 2048 / 2; shopItem.y = 2732 * 3 / 4; // Position at 3/4th height from the top // Update game every tick LK.on('tick', function () { // Game logic that needs to be updated every frame });
/****
* Classes
****/
// ShopItem class for buying more yogurt
var ShopItem = Container.expand(function () {
var self = Container.call(this);
var shopItemGraphic = self.attachAsset('shopItem', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
if (game.money >= game.yogurtCost) {
game.money -= game.yogurtCost;
game.yogurtCount += 1;
moneyTxt.setText("Money: $" + game.money);
yogurtCountTxt.setText("Yogurts: " + game.yogurtCount);
}
});
});
// Assets will be automatically created based on usage in the code.
// Yogurt class
var Yogurt = Container.expand(function () {
var self = Container.call(this);
var yogurtGraphic = self.attachAsset('yogurt', {
anchorX: 0.5,
anchorY: 0.5
});
self.on('down', function () {
game.money += game.earnAmount;
moneyTxt.setText("Money: $" + game.money);
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
// Game variables
game.money = 0;
game.earnAmount = 1;
game.yogurtCost = 10;
game.yogurtCount = 1;
// Money display
var moneyTxt = new Text2("Money: $" + game.money, {
size: 100,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0
});
LK.gui.top.addChild(moneyTxt);
// Yogurt count display
var yogurtCountTxt = new Text2("Yogurts: " + game.yogurtCount, {
size: 100,
fill: "#ffffff",
anchorX: 0.5,
anchorY: 0
});
LK.gui.topRight.addChild(yogurtCountTxt);
// Create a yogurt
var yogurt = game.addChild(new Yogurt());
yogurt.x = 2048 / 2;
yogurt.y = 2732 / 4; // Position at 1/4th height from the top
// Create a shop item to buy more yogurt
var shopItem = game.addChild(new ShopItem());
shopItem.x = 2048 / 2;
shopItem.y = 2732 * 3 / 4; // Position at 3/4th height from the top
// Update game every tick
LK.on('tick', function () {
// Game logic that needs to be updated every frame
});