about summary refs log tree commit diff stats
path: root/js
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-12-29 13:11:09 -0500
committerelioat <elioat@tilde.institute>2023-12-29 13:11:09 -0500
commitddb9cf300d5eb0696d5f466415e3c19018f5bc8c (patch)
tree5c33b603b8a8fad79e6be675ea3db4def807d392 /js
parentb63f67c6596cb93da7db010b7fd390ff75f7e892 (diff)
downloadtour-ddb9cf300d5eb0696d5f466415e3c19018f5bc8c.tar.gz
pushable items
Diffstat (limited to 'js')
-rw-r--r--js/game-frame/game.js88
1 files changed, 49 insertions, 39 deletions
diff --git a/js/game-frame/game.js b/js/game-frame/game.js
index fabc6bf..9a1b7fb 100644
--- a/js/game-frame/game.js
+++ b/js/game-frame/game.js
@@ -70,21 +70,22 @@ 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;
-}
+// // 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'),
-];
+// // Create some pushable items
+// let pushableItems = [
+//   new PushableItem(24, 48, player.width, player.height, 'green'),
+//   new PushableItem(48, 24, player.width, player.height, 'green'),
+//   new PushableItem(48, 248, player.width, player.height, 'green'),
+// ];
 
 
 
@@ -155,32 +156,41 @@ function gameLoop() {
 
 
 
-    // Draw pushable items
-    pushableItems.forEach(item => {
-      ctx.fillStyle = item.color;
-      ctx.fillRect(item.x, item.y, item.width, item.height);
-    });
+    // // Draw pushable items
+    // pushableItems.forEach(item => {
+    //   ctx.fillStyle = item.color;
+    //   ctx.fillRect(item.x, item.y, item.width, item.height);
+    // });    
+    
+    // // Determine if the player is about to push a pushable item
+    // let pushableItem = null;
+    // for (let i = 0; i < pushableItems.length; i++) {
+    //   if (player.x + player.width === pushableItems[i].x && player.y === pushableItems[i].y) {
+    //     pushableItem = pushableItems[i];
+    //   }
+    // }
+
+    // // If there is a pushable item, check if the player can push it
+    // if (pushableItem) {
+    //   // Calculate the next pixel coordinates
+    //   const nextX = pushableItem.x + player.step;
+    //   const nextY = pushableItem.y + player.step;
+
+    //   // Calculate the tile coordinates
+    //   const tileX = Math.floor(nextX / TILE_SIZE);
+    //   const tileY = Math.floor(nextY / TILE_SIZE);
+
+    //   // Check if the next pixel is within the map boundaries
+    //   if (nextX >= 0 && nextX < canvas.width && nextY >= 0 && nextY < canvas.height) {
+    //     // Check if the next pixel is walkable
+    //     if (map[tileY] && map[tileY][tileX] && map[tileY][tileX].walkable) {
+    //       // Update the pushable item's position
+    //       pushableItem.x = nextX;
+    //     }
+    //   }
+    // }
 
-    // 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;
-        }
-      }
-    }
+