diff options
Diffstat (limited to 'js/game-frame/game.js')
-rw-r--r-- | js/game-frame/game.js | 54 |
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(); |