===================================================================
--- original.js
+++ change.js
@@ -94,12 +94,22 @@
// Create floor instance
var floor = game.addChild(new Floor());
floor.x = 2048 / 2;
floor.y = game.groundLevel + 25; // Adjust y position to align with ground level
-// Create cactus instance
-var cactus = game.addChild(new Cactus());
-cactus.x = 1500;
-cactus.y = game.groundLevel - 100; // Adjust y position to align with ground level
+// Create looped cactus instances
+function createCactus() {
+ var cactus = new Cactus();
+ cactus.x = 2048;
+ cactus.y = game.groundLevel - 100; // Adjust y position to align with ground level
+ game.addChild(cactus);
+ return cactus;
+}
+var cacti = [];
+for (var i = 0; i < 5; i++) {
+ var cactus = createCactus();
+ cactus.x += i * 500; // Space out cacti
+ cacti.push(cactus);
+}
// Create player instance
var player = game.addChild(new Player());
player.x = 200;
player.y = game.groundLevel;
@@ -131,8 +141,15 @@
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
+ // Update cacti positions
+ for (var j = cacti.length - 1; j >= 0; j--) {
+ cacti[j].update();
+ if (cacti[j].x < -cacti[j].width) {
+ cacti[j].x = 2048 + cacti[j].width; // Reset cactus position to the right
+ }
+ }
if (LK.ticks % 60 == 0) {
spawnObstacle();
game.score++;
scoreTxt.setText(game.score);