diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/sand/sand.js | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/js/sand/sand.js b/js/sand/sand.js index b2dbb03..d241079 100644 --- a/js/sand/sand.js +++ b/js/sand/sand.js @@ -102,17 +102,9 @@ window.addEventListener('keydown', (e) => { grid[y][x] = 0; grid[y][x + 1] = 3; return; - } else if ((e.key === ' ' || e.key === 'ArrowUp' || e.key === 'w') && (y === gridHeight - 1 || grid[y + 1][x] !== 0)) { - let jumpCount = 0; - function jump() { - if (jumpCount < jumpHeight && y - jumpCount >= 0 && grid[y - jumpCount - 1][x] === 0) { - grid[y - jumpCount][x] = 0; - grid[y - jumpCount - 1][x] = 3; - jumpCount++; - setTimeout(jump, 100); // delay in milliseconds - } - } - jump(); + } else if ((e.key === ' ' || e.key === 'ArrowUp' || e.key === 'w') && y < gridHeight - 1 && grid[y + 1][x] !== 0) { + grid[y][x] = 0; + grid[Math.max(y - jumpHeight, 0)][x] = 3; return; } } |