/****
* Classes
****/
// Assets will be automatically created and loaded during gameplay
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = 0; // 0: right, 1: down, 2: left, 3: up
self.update = function () {
switch (self.direction) {
case 0:
self.x += self.speed;
break;
case 1:
self.y += self.speed;
break;
case 2:
self.x -= self.speed;
break;
case 3:
self.y -= self.speed;
break;
}
// Boundary check
if (self.x < 0) {
self.x = 0;
}
if (self.x > 2048) {
self.x = 2048;
}
if (self.y < 0) {
self.y = 0;
}
if (self.y > 2732) {
self.y = 2732;
}
};
self.changeDirection = function () {
self.direction = (self.direction + 1) % 4;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Change background color to sky blue
});
/****
* Game Code
****/
var ball = game.addChild(new Ball());
ball.x = 1024; // Center horizontally
ball.y = 1366; // Center vertically
game.down = function (x, y, obj) {
ball.changeDirection();
};
game.update = function () {
ball.update();
};