/**** * Classes ****/ // Define a Chaser class var Chaser = Container.expand(function () { var self = Container.call(this); var chaserGraphics = self.attachAsset('chaser', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.update = function () { // Update chaser position to follow the player var dx = player.x - self.x; var dy = player.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { self.x += dx / distance * self.speed; self.y += dy / distance * self.speed; } }; }); //<Assets used in the game will automatically appear here> // Define a Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Player update logic }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundImage: 'Fon' // Set background image using asset ID }); /**** * Game Code ****/ // Initialize timer var elapsedTime = 0; var timerText = new Text2('Time: 0', { size: 100, fill: "#ffffff" }); timerText.anchor.set(0.5, 0); LK.gui.top.addChild(timerText); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var chaser1 = game.addChild(new Chaser()); chaser1.x = 100; chaser1.y = 100; var chaser2 = game.addChild(new Chaser()); chaser2.x = 300; chaser2.y = 300; var chaser3 = game.addChild(new Chaser()); chaser3.x = 500; chaser3.y = 500; var chaser4 = game.addChild(new Chaser()); chaser4.x = 700; chaser4.y = 700; var chaser5 = game.addChild(new Chaser()); chaser5.x = 900; chaser5.y = 900; // Handle player movement game.down = function (x, y, obj) { player.x = x; player.y = y; // Update timer if (LK.ticks % 60 === 0) { // Assuming 60 FPS, update every second elapsedTime++; timerText.setText('Time: ' + elapsedTime); } }; // Update game logic game.update = function () { // Update timer if (LK.ticks % 60 === 0) { // Assuming 60 FPS, update every second elapsedTime++; timerText.setText('Time: ' + elapsedTime); } // Check for collision with chaser1 if (player.intersects(chaser1)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check for collision with chaser2 if (player.intersects(chaser2)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check for collision with chaser3 if (player.intersects(chaser3)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check for collision with chaser4 if (player.intersects(chaser4)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Check for collision with chaser5 if (player.intersects(chaser5)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -37,9 +37,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundImage: 'backgroundImageId' // Set background image using asset ID
+ backgroundImage: 'Fon' // Set background image using asset ID
});
/****
* Game Code