/****
* Classes
****/
// The game engine will automatically create and load the assets
// Create a class for the cycle
var Cycle = Container.expand(function () {
var self = Container.call(this);
var cycleGraphics = self.attachAsset('cycle', {
anchorX: 0.5,
anchorY: 0.5
});
self.distanceTravelled = 0;
self.update = function () {
if (self.distanceTravelled < 5000) {
self.distanceTravelled += 5;
} else {
LK.showGameOver();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the cycle
var cycle = game.addChild(new Cycle());
cycle.x = 2048 / 2;
cycle.y = 2732 / 2;
// Display the distance travelled by the cycle
var distanceTxt = new Text2('0 km', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(distanceTxt);
// Update the game every tick
game.update = function () {
cycle.update();
distanceTxt.setText(cycle.distanceTravelled + ' km');
};