/****
* 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 () {};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Add village background to the game
var villageBackground = LK.getAsset('villageBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(villageBackground);
// 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');
}; ===================================================================
--- original.js
+++ change.js
@@ -9,15 +9,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.distanceTravelled = 0;
- self.update = function () {
- if (self.distanceTravelled < 5000) {
- self.distanceTravelled += 5;
- } else {
- LK.showGameOver();
- }
- };
+ self.update = function () {};
});
/****
* Initialize Game