===================================================================
--- original.js
+++ change.js
@@ -107,13 +107,16 @@
LK.showGameOver();
}
});
obstacles.forEach(function (obstacle) {
- if (!player.intersects(obstacle) && obstacle.x < player.x) {
- score += Math.floor(LK.ticks / 600); // Increase score incrementally
+ if (!obstacle.scored && !player.intersects(obstacle) && obstacle.x < player.x) {
+ score += 1; // Increase score by 1 for each avoided obstacle
scoreTxt.setText('Score: ' + score);
- obstacle.x = 2048 + Math.random() * 2048; // Reset obstacle position
+ obstacle.scored = true; // Mark obstacle as scored
}
+ if (obstacle.x > player.x) {
+ obstacle.scored = false; // Reset scored status when obstacle is ahead
+ }
});
if (player.intersects(enemy) || obstacles.some(function (obstacle) {
return player.intersects(obstacle);
})) {