about summary refs log tree commit diff stats
path: root/js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-12-28 20:04:48 -0500
committerelioat <elioat@tilde.institute>2023-12-28 20:04:48 -0500
commit37b9b5ad35f2d49f02914b4df82c2432883d6412 (patch)
tree5654e1158e61fbe67456c2df717bd68817ec3af5 /js
parent2768352165dea9aa273a500885d4cea71becbdcd (diff)
downloadtour-37b9b5ad35f2d49f02914b4df82c2432883d6412.tar.gz
*
Diffstat (limited to 'js')
-rw-r--r--js/game-frame/game.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/js/game-frame/game.js b/js/game-frame/game.js
index f63b835..fabc6bf 100644
--- a/js/game-frame/game.js
+++ b/js/game-frame/game.js
@@ -70,6 +70,23 @@ let items = [
 ];
 
 
+// Pushable items
+// Define the PushableItem class
+function PushableItem(x, y, width, height, color) {
+  this.x = x;
+  this.y = y;
+  this.width = width;
+  this.height = height;
+  this.color = color;
+}
+
+// Create some pushable items
+let pushableItems = [
+  new PushableItem(24, 48, player.width, player.height, 'green'),
+  new PushableItem(48, 24, player.width, player.height, 'green'),
+];
+
+
 
 
 
@@ -92,6 +109,9 @@ function displayStats() {
 
 
 
+
+
+
 // Game loop
 function gameLoop() {
     // Clear the canvas
@@ -134,6 +154,40 @@ function gameLoop() {
     }
 
 
+
+    // Draw pushable items
+    pushableItems.forEach(item => {
+      ctx.fillStyle = item.color;
+      ctx.fillRect(item.x, item.y, item.width, item.height);
+    });
+
+    // Handle pushable items
+    // FIXME: this doesn't work correctly
+    for (let i = 0; i < pushableItems.length; i++) {
+      if (player.x === pushableItems[i].x && player.y === pushableItems[i].y) {
+        // Calculate the tile coordinates
+        const tileX = Math.floor(pushableItems[i].x / TILE_SIZE);
+        const tileY = Math.floor(pushableItems[i].y / TILE_SIZE);
+
+        // Calculate the new position
+        let newX = pushableItems[i].x + player.step;
+        let newY = pushableItems[i].y + player.step;
+
+        // Check if the new tile is walkable
+        if (map[tileY] && map[tileY][tileX] && map[tileY][tileX].walkable) {
+          // Update the item's position
+          pushableItems[i].x = newX;
+          pushableItems[i].y = newY;
+        }
+      }
+    }
+    
+    
+
+
+    
+
+
     // Call the game loop again next frame
     requestAnimationFrame(gameLoop);
     displayStats();