/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine.
// Bubble class
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y -= 2;
if (self.y < -50) {
self.destroy();
}
};
self.down = function (x, y, obj) {
LK.setScore(LK.getScore() + 1);
self.destroy();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize bubble array
var bubbles = [];
// Game update function
game.update = function () {
// Update score display
scoreTxt.setText(LK.getScore());
// Create new bubbles
if (LK.ticks % 30 == 0) {
var newBubble = new Bubble();
newBubble.x = Math.random() * 2048;
newBubble.y = 2732;
bubbles.push(newBubble);
game.addChild(newBubble);
}
// Remove bubbles that have moved off screen
for (var i = bubbles.length - 1; i >= 0; i--) {
if (bubbles[i].y < -50) {
bubbles[i].destroy();
bubbles.splice(i, 1);
}
}
};