var Hurdle = Container.expand(function () {
var self = Container.call(this);
var hurdleGraphics = self.createAsset('hurdle', 'Hurdle Graphics', .5, .5);
hurdleGraphics.hitArea = new Rectangle(-hurdleGraphics.width * 0.2 / 2, -hurdleGraphics.height * 0.2 / 2, hurdleGraphics.width * 0.8, hurdleGraphics.height * 0.8);
self.speed = -5;
self.move = function () {
self.x += self.speed;
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player Graphics', .5, .5);
playerGraphics.hitArea = new Rectangle(-playerGraphics.width * 0.105 / 2, -playerGraphics.height * 0.105 / 2, playerGraphics.width * 0.21, playerGraphics.height * 0.21);
playerGraphics.tint = 0xFF0000;
self.jump = function () {
if (self.y === 2000) {
var jumpHeight = 330;
var jumpSpeed = 10;
var jumpTick = 0;
var rotationSpeed = 0.1;
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: '#ffffff'
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
var jumpingInterval = LK.setInterval(function () {
if (jumpTick < jumpHeight) {
self.y -= jumpSpeed;
jumpTick += jumpSpeed;
self.rotation += rotationSpeed;
} else if (self.y < 2000) {
self.y += jumpSpeed;
self.rotation += rotationSpeed;
}
if (self.y >= 2000) {
self.y = 2000;
self.rotation = 0;
LK.clearInterval(jumpingInterval);
this.score++;
scoreTxt.setText(this.score.toString());
}
}, 21);
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
LK.stageContainer.setBackgroundColor(0xADD8E6);
var player = self.addChild(new Player());
player.x = 200;
player.y = 2000;
var score = 0;
var groundGraphics = self.createAsset('ground', 'Ground Graphics', 0, 1);
groundGraphics.width = 2048;
groundGraphics.height = (2732 - player.y) * 0.8;
groundGraphics.y = player.y + groundGraphics.height / 2 + groundGraphics.height * 0.4 + 100;
groundGraphics.tint = 0x008000;
var hurdles = [];
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: '#ffffff'
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
LK.on('tick', function () {
for (var a = hurdles.length - 1; a >= 0; a--) {
if (hurdles[a]) {
hurdles[a].move();
if (hurdles[a].x < -50) {
hurdles[a].destroy();
hurdles.splice(a, 1);
}
if (player.intersects(hurdles[a])) {
LK.showGameOver();
}
}
}
if (LK.ticks % 96 == 0) {
var newHurdle = new Hurdle();
newHurdle.x = 2048;
newHurdle.y = 2000;
hurdles.push(newHurdle);
self.addChild(newHurdle);
}
});
stage.on('down', function (obj) {
player.jump();
});
});