about summary refs log tree commit diff stats
path: root/html/isometric-bounce/js/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/isometric-bounce/js/game.js')
-rw-r--r--html/isometric-bounce/js/game.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/html/isometric-bounce/js/game.js b/html/isometric-bounce/js/game.js
index fb6530d..e2b0021 100644
--- a/html/isometric-bounce/js/game.js
+++ b/html/isometric-bounce/js/game.js
@@ -8,6 +8,7 @@ function createGame() {
         offsetX: 0,
         offsetY: 0,
         particles: [],
+        lastFrameTime: 0,
         player: {
             x: 0,
             y: 0,
@@ -251,14 +252,22 @@ function createGame() {
         state.ctx.stroke();
     }
 
-    function gameLoop() {
-        state.ctx.clearRect(0, 0, state.canvas.width, state.canvas.height);
+    function gameLoop(timestamp) {
+        // Set target frame duration for 60 FPS (approximately 16.67ms)
+        const frameInterval = 1000 / 60;
         
-        drawGrid();
-        updateParticles();
-        drawParticles();
-        updatePlayer();
-        drawPlayer();
+        // If we haven't stored the last frame time, or enough time has passed
+        if (!state.lastFrameTime || timestamp - state.lastFrameTime >= frameInterval) {
+            state.ctx.clearRect(0, 0, state.canvas.width, state.canvas.height);
+            
+            drawGrid();
+            updateParticles();
+            drawParticles();
+            updatePlayer();
+            drawPlayer();
+            
+            state.lastFrameTime = timestamp;
+        }
         
         requestAnimationFrame(gameLoop);
     }
@@ -291,6 +300,7 @@ function createGame() {
         resizeCanvas();
         window.addEventListener('resize', resizeCanvas);
         state.canvas.addEventListener('click', handleClick);
+        state.lastFrameTime = 0;
         gameLoop();
     }