/**** * 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('cycleImage', { anchorX: 0.5, anchorY: 0.5 }); self.distanceTravelled = 0; self.update = function () { // Logic for cycle movement can be added here if needed }; }); /**** * 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; // Add tap event to move the cycle forward game.down = function (x, y, obj) { cycle.distanceTravelled += 0.1; // Increase distance by 0.1 km per tap }; // 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'); };
/****
* 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('cycleImage', {
anchorX: 0.5,
anchorY: 0.5
});
self.distanceTravelled = 0;
self.update = function () {
// Logic for cycle movement can be added here if needed
};
});
/****
* 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;
// Add tap event to move the cycle forward
game.down = function (x, y, obj) {
cycle.distanceTravelled += 0.1; // Increase distance by 0.1 km per tap
};
// 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');
};