===================================================================
--- original.js
+++ change.js
@@ -9,9 +9,16 @@
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
- // Chaser update logic
+ // 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
@@ -72,14 +79,8 @@
// Assuming 60 FPS, update every second
elapsedTime++;
timerText.setText('Time: ' + elapsedTime);
}
- // Move chaser1 randomly
- chaser1.x += (Math.random() - 0.5) * chaser1.speed;
- chaser1.y += (Math.random() - 0.5) * chaser1.speed;
- // Move chaser2 randomly
- chaser2.x += (Math.random() - 0.5) * chaser2.speed;
- chaser2.y += (Math.random() - 0.5) * chaser2.speed;
// Check for collision with chaser1
if (player.intersects(chaser1)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();