about summary refs log tree commit diff stats
path: root/html/isometric-bounce/js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-12-29 17:29:12 -0500
committerelioat <elioat@tilde.institute>2024-12-29 17:29:12 -0500
commit4a0b56372d3ab3db7b25c1bf191c0effd06181a4 (patch)
treef8665d84db601887c78c81902462bdc8ae4a4b3c /html/isometric-bounce/js
parent56375df183c97b1f5b5121af82aa024b918af88a (diff)
downloadtour-4a0b56372d3ab3db7b25c1bf191c0effd06181a4.tar.gz
*
Diffstat (limited to 'html/isometric-bounce/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();
     }