/****
* 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.speedX = 5;
self.speedY = 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -1;
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -1;
}
};
});
// Goal class
var Goal = Container.expand(function () {
var self = Container.call(this);
var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5
});
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player update logic
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var ball = game.addChild(new Ball());
ball.x = 1024;
ball.y = 1366;
var player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
var goal = game.addChild(new Goal());
goal.x = 1024;
goal.y = 100;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var score = 0;
game.update = function () {
if (ball.intersects(goal)) {
score += 1;
scoreTxt.setText(score);
ball.x = 1024;
ball.y = 1366;
}
};
game.down = function (x, y, obj) {
player.x = x;
player.y = y;
};
game.move = function (x, y, obj) {
player.x = x;
player.y = y;
};