From 56917474fdf577dea7a19c99956a3f06dc6f574d Mon Sep 17 00:00:00 2001 From: "Z. Cliffe Schreuders" Date: Mon, 17 Nov 2025 19:47:55 +0000 Subject: [PATCH] fix: Add full tile collision boxes above and below side doors for improved player interaction --- js/systems/collision.js | 66 +++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/js/systems/collision.js b/js/systems/collision.js index b6016bb..92f0dbb 100644 --- a/js/systems/collision.js +++ b/js/systems/collision.js @@ -280,6 +280,54 @@ export function removeTilesUnderDoor(wallLayer, roomId, position) { console.log(`Recalculating collision for wall layer in ${roomId} after removing ${tilesToRemove.length} tiles`); wallLayer.setCollisionByExclusion([-1]); } + + // For side doors (E/W) in the CURRENT room, add full tile collision boxes on N/S sides + if (direction === 'east' || direction === 'west') { + console.log(`Adding full tile collision boxes above and below side door cutout in current room ${roomId}`); + + const room = window.rooms ? window.rooms[roomId] : null; + if (room) { + // North side collision box (full tile above the door) + const northCollisionBox = gameRef.add.rectangle( + doorX, + doorY - TILE_SIZE, // One full tile above the door + TILE_SIZE, + TILE_SIZE, // Full tile size + 0x0000ff, + 0 // Invisible + ); + northCollisionBox.setVisible(false); + gameRef.physics.add.existing(northCollisionBox, true); + northCollisionBox.body.immovable = true; + + // South side collision box (full tile below the door) + const southCollisionBox = gameRef.add.rectangle( + doorX, + doorY + TILE_SIZE, // One full tile below the door + TILE_SIZE, + TILE_SIZE, // Full tile size + 0x0000ff, + 0 // Invisible + ); + southCollisionBox.setVisible(false); + gameRef.physics.add.existing(southCollisionBox, true); + southCollisionBox.body.immovable = true; + + // Add collision with player + const player = window.player; + if (player && player.body) { + gameRef.physics.add.collider(player, northCollisionBox); + gameRef.physics.add.collider(player, southCollisionBox); + console.log(`Added full tile collision boxes above and below side door in ${roomId}`); + } + + // Store collision boxes in room for cleanup + if (!room.wallCollisionBoxes) { + room.wallCollisionBoxes = []; + } + room.wallCollisionBoxes.push(northCollisionBox, southCollisionBox); + } + } }); } @@ -494,16 +542,16 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door wallLayer.setCollisionByExclusion([-1]); } - // For side doors (E/W), add collision boxes on N/S sides of the cut-out tile + // For side doors (E/W), add full tile collision boxes above and below the cut-out if (oppositeDirection === 'east' || oppositeDirection === 'west') { - console.log(`Adding collision boxes on N/S sides of side door cutout in ${roomId}`); + console.log(`Adding full tile collision boxes above and below side door cutout in ${roomId}`); - // North side collision box + // North side collision box (full tile above the door) const northCollisionBox = gameRef.add.rectangle( doorX, - doorY - (TILE_SIZE / 2) - 4, // Above the door, 4px inset + doorY - TILE_SIZE, // One full tile above the door TILE_SIZE, - 8, // Thicker collision box + TILE_SIZE, // Full tile size 0x0000ff, 0 // Invisible ); @@ -511,12 +559,12 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door gameRef.physics.add.existing(northCollisionBox, true); northCollisionBox.body.immovable = true; - // South side collision box + // South side collision box (full tile below the door) const southCollisionBox = gameRef.add.rectangle( doorX, - doorY + (TILE_SIZE / 2) + 4, // Below the door, 4px inset + doorY + TILE_SIZE, // One full tile below the door TILE_SIZE, - 8, // Thicker collision box + TILE_SIZE, // Full tile size 0x0000ff, 0 // Invisible ); @@ -529,7 +577,7 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door if (player && player.body) { gameRef.physics.add.collider(player, northCollisionBox); gameRef.physics.add.collider(player, southCollisionBox); - console.log(`Added N/S collision boxes for side door in ${roomId}`); + console.log(`Added full tile collision boxes above and below side door in ${roomId}`); } // Store collision boxes in room for cleanup