/****
* Classes
****/
var GoldCoin = Container.expand(function () {
var self = Container.call(this);
var goldCoinGraphics = self.attachAsset('goldCoin', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.alpha -= 0.01;
if (self.alpha <= 0 || self.y > 2732) {
self.x = rabbit.x;
self.y = rabbit.y - (150 + (LK.getScore() - 1) * 20);
self.alpha = 1;
}
};
});
/****
* Initialize Game
****/
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var forestBackground = game.attachAsset('forest', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0
});
var rabbit = game.attachAsset('rabbit', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
rabbit.down = function (x, y, obj) {
var _this = this;
LK.setScore(LK.getScore() + 1);
counterTxt.setText(LK.getScore());
var goldCoin = game.addChild(new GoldCoin());
goldCoin.x = this.x;
goldCoin.y = this.y - (150 + (LK.getScore() - 1) * 20);
};
rabbit.up = function (x, y, obj) {};
// Update function to handle game logic
var counterTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
counterTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(counterTxt);
game.update = function () {
if (LK.getScore() === 45) {
var goldCoin = game.addChild(new GoldCoin());
goldCoin.x = rabbit.x;
goldCoin.y = rabbit.y - (150 + (LK.getScore() - 1) * 20);
}
};