/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Class for Pou, the pet var Pou = Container.expand(function () { var self = Container.call(this); var pouGraphics = self.attachAsset('pou', { anchorX: 0.5, anchorY: 0.5 }); self.hunger = 100; self.energy = 100; self.happiness = 100; self.update = function () { // Decrease stats over time self.hunger -= 0.05; self.energy -= 0.02; self.happiness -= 0.03; // Check if Pou is dead if (self.hunger <= 0 || self.energy <= 0 || self.happiness <= 0) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }; self.feed = function () { self.hunger = Math.min(self.hunger + 20, 100); }; self.play = function () { self.happiness = Math.min(self.happiness + 20, 100); }; self.sleep = function () { self.energy = Math.min(self.energy + 20, 100); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var pou = game.addChild(new Pou()); pou.x = 2048 / 2; pou.y = 2732 / 2; var hungerText = new Text2('Hunger: 100', { size: 50, fill: "#ffffff" }); hungerText.anchor.set(0.5, 0); LK.gui.topLeft.addChild(hungerText); var energyText = new Text2('Energy: 100', { size: 50, fill: "#ffffff" }); energyText.anchor.set(0.5, 0); LK.gui.top.addChild(energyText); var happinessText = new Text2('Happiness: 100', { size: 50, fill: "#ffffff" }); happinessText.anchor.set(0.5, 0); LK.gui.topRight.addChild(happinessText); game.update = function () { hungerText.setText('Hunger: ' + Math.floor(pou.hunger)); energyText.setText('Energy: ' + Math.floor(pou.energy)); happinessText.setText('Happiness: ' + Math.floor(pou.happiness)); }; game.down = function (x, y, obj) { var game_position = game.toLocal(obj.global); if (game_position.x < 2048 / 4) { pou.feed(); } else if (game_position.x < 2048 * 2 / 4) { pou.play(); } else if (game_position.x < 2048 * 3 / 4) { pou.sleep(); } else { // Open shop, play games, or go to bed } };
/****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Class for Pou, the pet
var Pou = Container.expand(function () {
var self = Container.call(this);
var pouGraphics = self.attachAsset('pou', {
anchorX: 0.5,
anchorY: 0.5
});
self.hunger = 100;
self.energy = 100;
self.happiness = 100;
self.update = function () {
// Decrease stats over time
self.hunger -= 0.05;
self.energy -= 0.02;
self.happiness -= 0.03;
// Check if Pou is dead
if (self.hunger <= 0 || self.energy <= 0 || self.happiness <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
self.feed = function () {
self.hunger = Math.min(self.hunger + 20, 100);
};
self.play = function () {
self.happiness = Math.min(self.happiness + 20, 100);
};
self.sleep = function () {
self.energy = Math.min(self.energy + 20, 100);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var pou = game.addChild(new Pou());
pou.x = 2048 / 2;
pou.y = 2732 / 2;
var hungerText = new Text2('Hunger: 100', {
size: 50,
fill: "#ffffff"
});
hungerText.anchor.set(0.5, 0);
LK.gui.topLeft.addChild(hungerText);
var energyText = new Text2('Energy: 100', {
size: 50,
fill: "#ffffff"
});
energyText.anchor.set(0.5, 0);
LK.gui.top.addChild(energyText);
var happinessText = new Text2('Happiness: 100', {
size: 50,
fill: "#ffffff"
});
happinessText.anchor.set(0.5, 0);
LK.gui.topRight.addChild(happinessText);
game.update = function () {
hungerText.setText('Hunger: ' + Math.floor(pou.hunger));
energyText.setText('Energy: ' + Math.floor(pou.energy));
happinessText.setText('Happiness: ' + Math.floor(pou.happiness));
};
game.down = function (x, y, obj) {
var game_position = game.toLocal(obj.global);
if (game_position.x < 2048 / 4) {
pou.feed();
} else if (game_position.x < 2048 * 2 / 4) {
pou.play();
} else if (game_position.x < 2048 * 3 / 4) {
pou.sleep();
} else {
// Open shop, play games, or go to bed
}
};