Spaces:
Running
Running
🐳 13/02 - 02:43 - The red devourer only moves once every time that you move twice.
Browse files
game.js
CHANGED
|
@@ -21,6 +21,10 @@ const enemy = {
|
|
| 21 |
stolenScore: 0
|
| 22 |
};
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
const toppings = {
|
| 25 |
beef: [],
|
| 26 |
lettuce: [],
|
|
@@ -62,6 +66,10 @@ function createTopping(type) {
|
|
| 62 |
function movePlayer(e) {
|
| 63 |
if (!gameRunning) return;
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
switch(e.key) {
|
| 66 |
case 'ArrowUp': player.y -= player.speed; break;
|
| 67 |
case 'ArrowDown': player.y += player.speed; break;
|
|
@@ -72,11 +80,19 @@ function movePlayer(e) {
|
|
| 72 |
// Boundary check
|
| 73 |
player.x = Math.max(player.radius, Math.min(canvas.width - player.radius, player.x));
|
| 74 |
player.y = Math.max(player.radius, Math.min(canvas.height - player.radius, player.y));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
}
|
| 76 |
|
| 77 |
function moveEnemy() {
|
| 78 |
if (!gameRunning) return;
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
// Calculate direction to player
|
| 81 |
const dx = player.x - enemy.x;
|
| 82 |
const dy = player.y - enemy.y;
|
|
|
|
| 21 |
stolenScore: 0
|
| 22 |
};
|
| 23 |
|
| 24 |
+
let playerMoveCount = 0;
|
| 25 |
+
let lastPlayerX = null;
|
| 26 |
+
let lastPlayerY = null;
|
| 27 |
+
|
| 28 |
const toppings = {
|
| 29 |
beef: [],
|
| 30 |
lettuce: [],
|
|
|
|
| 66 |
function movePlayer(e) {
|
| 67 |
if (!gameRunning) return;
|
| 68 |
|
| 69 |
+
// Store position before move
|
| 70 |
+
lastPlayerX = player.x;
|
| 71 |
+
lastPlayerY = player.y;
|
| 72 |
+
|
| 73 |
switch(e.key) {
|
| 74 |
case 'ArrowUp': player.y -= player.speed; break;
|
| 75 |
case 'ArrowDown': player.y += player.speed; break;
|
|
|
|
| 80 |
// Boundary check
|
| 81 |
player.x = Math.max(player.radius, Math.min(canvas.width - player.radius, player.x));
|
| 82 |
player.y = Math.max(player.radius, Math.min(canvas.height - player.radius, player.y));
|
| 83 |
+
|
| 84 |
+
// Only count as a move if position actually changed
|
| 85 |
+
if (player.x !== lastPlayerX || player.y !== lastPlayerY) {
|
| 86 |
+
playerMoveCount++;
|
| 87 |
+
}
|
| 88 |
}
|
| 89 |
|
| 90 |
function moveEnemy() {
|
| 91 |
if (!gameRunning) return;
|
| 92 |
|
| 93 |
+
// Enemy only moves once for every 2 player moves
|
| 94 |
+
if (playerMoveCount % 2 !== 0) return;
|
| 95 |
+
|
| 96 |
// Calculate direction to player
|
| 97 |
const dx = player.x - enemy.x;
|
| 98 |
const dy = player.y - enemy.y;
|