/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine
// Bubble Ball class
var BubbleBall = Container.expand(function () {
var self = Container.call(this);
var bubbleBallGraphics = self.attachAsset('bubbleBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
};
});
// Paddle class
var Paddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.attachAsset('paddle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Paddle movement will be handled in game.update
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize paddle and bubble ball
var paddle = game.addChild(new Paddle());
paddle.x = 2048 / 2;
paddle.y = 2732 - paddle.height;
var bubbleBall = game.addChild(new BubbleBall());
bubbleBall.x = 2048 / 2;
bubbleBall.y = bubbleBall.height;
// Handle paddle movement
var dragNode = null;
game.down = function (x, y, obj) {
dragNode = paddle;
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Update game state
game.update = function () {
// Bounce the bubble ball off the walls
if (bubbleBall.x < 0 || bubbleBall.x > 2048) {
bubbleBall.speed = -bubbleBall.speed;
}
// Bounce the bubble ball off the paddle
if (bubbleBall.intersects(paddle)) {
bubbleBall.speed = -bubbleBall.speed;
}
// End the game if the bubble ball hits the bottom of the screen
if (bubbleBall.y > 2732) {
LK.showGameOver();
}
};