From 616f4b486e2f1aa46a07218b086f406ae738f472 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Nov 2025 12:33:31 +0000 Subject: [PATCH] fix: Correct side door (E/W) positioning and tile removal - Position side doors 2 tiles from top (along the wall), not 3 tiles forward into the room - Remove only 1 tile under side door sprite, not 3 tiles - Update planning notes to reflect correct behavior Side doors (East/West) are now properly aligned with the wall and only remove the single tile directly under the door sprite, matching the specification for single-tile-tall side door sprites. This fixes the issue where side doors were positioned 1 tile too far forward into the room and were removing too many wall tiles. --- js/systems/collision.js | 10 +- js/systems/doors.js | 12 +-- .../new_room_layout/DOOR_PLACEMENT.md | 92 +++---------------- 3 files changed, 22 insertions(+), 92 deletions(-) diff --git a/js/systems/collision.js b/js/systems/collision.js index 2b931b6..f66a1f5 100644 --- a/js/systems/collision.js +++ b/js/systems/collision.js @@ -369,9 +369,9 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door doorWidth = TILE_SIZE * 2; doorHeight = TILE_SIZE; } else if (direction === 'east' || direction === 'west') { - // For east/west connections: positioned 3 tiles down from top corner - // Passage cutout is 3 tiles wide vertically - doorY = roomPosition.y + (TILE_SIZE * 3); // 3 tiles from top corner + // For east/west connections: positioned 2 tiles down from top (along the wall) + // Tile removal is 1 tile (under the door sprite) + doorY = roomPosition.y + (TILE_SIZE * 2); // 2 tiles from top (along the wall) if (direction === 'east') { // Original door is east, so new door should be west @@ -380,9 +380,9 @@ export function removeWallTilesForDoorInRoom(roomId, fromRoomId, direction, door // Original door is west, so new door should be east doorX = roomPosition.x + roomWidth - TILE_SIZE; } - // Side doors have a 3-tile wide passage (vertically) + // Side doors only remove 1 tile (under the door sprite) doorWidth = TILE_SIZE; - doorHeight = TILE_SIZE * 3; + doorHeight = TILE_SIZE; } else { console.log(`Unknown direction: ${direction}`); return; diff --git a/js/systems/doors.js b/js/systems/doors.js index 1e65d3a..7bfdc17 100644 --- a/js/systems/doors.js +++ b/js/systems/doors.js @@ -221,7 +221,7 @@ function placeEastDoorSingle(roomId, roomPosition, roomDimensions, connectedRoom const roomWidthPx = roomDimensions.widthPx; const doorX = roomPosition.x + roomWidthPx - TILE_SIZE; - const doorY = roomPosition.y + (TILE_SIZE * 3); // 3 tiles from top corner + const doorY = roomPosition.y + (TILE_SIZE * 2); // 2 tiles from top (along the wall) return { x: doorX, y: doorY, connectedRoom }; } @@ -237,11 +237,11 @@ function placeEastDoorsMultiple(roomId, roomPosition, roomDimensions, connectedR const doorX = roomPosition.x + roomWidthPx - TILE_SIZE; if (connectedRooms.length === 1) { - const doorY = roomPosition.y + (TILE_SIZE * 3); + const doorY = roomPosition.y + (TILE_SIZE * 2); doorPositions.push({ x: doorX, y: doorY, connectedRoom: connectedRooms[0] }); } else { // Multiple doors - space vertically - const topY = roomPosition.y + (TILE_SIZE * 3); + const topY = roomPosition.y + (TILE_SIZE * 2); const bottomY = roomPosition.y + roomHeightPx - (TILE_SIZE * 3); const spacing = (bottomY - topY) / (connectedRooms.length - 1); @@ -259,7 +259,7 @@ function placeEastDoorsMultiple(roomId, roomPosition, roomDimensions, connectedR */ function placeWestDoorSingle(roomId, roomPosition, roomDimensions, connectedRoom) { const doorX = roomPosition.x + TILE_SIZE; - const doorY = roomPosition.y + (TILE_SIZE * 3); // 3 tiles from top corner + const doorY = roomPosition.y + (TILE_SIZE * 2); // 2 tiles from top (along the wall) return { x: doorX, y: doorY, connectedRoom }; } @@ -274,11 +274,11 @@ function placeWestDoorsMultiple(roomId, roomPosition, roomDimensions, connectedR const doorX = roomPosition.x + TILE_SIZE; if (connectedRooms.length === 1) { - const doorY = roomPosition.y + (TILE_SIZE * 3); + const doorY = roomPosition.y + (TILE_SIZE * 2); doorPositions.push({ x: doorX, y: doorY, connectedRoom: connectedRooms[0] }); } else { // Multiple doors - space vertically - const topY = roomPosition.y + (TILE_SIZE * 3); + const topY = roomPosition.y + (TILE_SIZE * 2); const bottomY = roomPosition.y + roomHeightPx - (TILE_SIZE * 3); const spacing = (bottomY - topY) / (connectedRooms.length - 1); diff --git a/planning_notes/new_room_layout/DOOR_PLACEMENT.md b/planning_notes/new_room_layout/DOOR_PLACEMENT.md index b50c9ee..faa2fd9 100644 --- a/planning_notes/new_room_layout/DOOR_PLACEMENT.md +++ b/planning_notes/new_room_layout/DOOR_PLACEMENT.md @@ -173,60 +173,25 @@ function placeSouthDoorSingle(roomId, roomPosition, roomDimensions, gridCoords, ### East Connections #### Single Door -- **Position**: North corner of east edge +- **Position**: Along the wall at east edge - **Inset**: 2 tiles from top (below visual wall) ```javascript -function placeEastDoorSingle(roomId, roomPosition, roomDimensions, - connectedRoom, gameScenario, allPositions, allDimensions) { +function placeEastDoorSingle(roomId, roomPosition, roomDimensions, connectedRoom) { const roomWidthPx = roomDimensions.widthPx; - // CRITICAL: Check if connected room has multiple west connections - const connectedRoomData = gameScenario.rooms[connectedRoom]; - const connectedWestConnections = connectedRoomData?.connections?.west; - - if (Array.isArray(connectedWestConnections) && connectedWestConnections.length > 1) { - // Connected room has multiple west doors - align with the correct one - const indexInArray = connectedWestConnections.indexOf(roomId); - - if (indexInArray >= 0) { - const connectedPos = allPositions[connectedRoom]; - const connectedDim = allDimensions[connectedRoom]; - - // Calculate door Y based on connected room's multi-door spacing - const doorCount = connectedWestConnections.length; - let alignedDoorY; - - if (doorCount === 1) { - alignedDoorY = connectedPos.y + (TILE_SIZE * 2); - } else if (indexInArray === 0) { - alignedDoorY = connectedPos.y + (TILE_SIZE * 2); - } else if (indexInArray === doorCount - 1) { - alignedDoorY = connectedPos.y + connectedDim.heightPx - (TILE_SIZE * 3); - } else { - const firstDoorY = connectedPos.y + (TILE_SIZE * 2); - const lastDoorY = connectedPos.y + connectedDim.heightPx - (TILE_SIZE * 3); - const spacing = (lastDoorY - firstDoorY) / (doorCount - 1); - alignedDoorY = firstDoorY + (spacing * indexInArray); - } - - const doorX = roomPosition.x + roomWidthPx - TILE_SIZE; - return { x: doorX, y: alignedDoorY }; - } - } - - // Default: place at north corner of east edge + // Position along the wall at the east edge const doorX = roomPosition.x + roomWidthPx - TILE_SIZE; - const doorY = roomPosition.y + (TILE_SIZE * 2); // Below visual wall + const doorY = roomPosition.y + (TILE_SIZE * 2); // 2 tiles from top (along the wall) - return { x: doorX, y: doorY }; + return { x: doorX, y: doorY, connectedRoom }; } ``` #### Multiple Doors - **First Door**: North corner (2 tiles from top) -- **Second Door**: 3 tiles up from south edge (avoids overlap) -- **More Doors**: Evenly spaced between first and second +- **Last Door**: 3 tiles up from south edge (avoids overlap) +- **More Doors**: Evenly spaced between first and last ```javascript function placeEastDoorsMultiple(roomId, roomPosition, roomDimensions, connectedRooms) { @@ -274,47 +239,12 @@ function placeEastDoorsMultiple(roomId, roomPosition, roomDimensions, connectedR Mirror of East connections: ```javascript -function placeWestDoorSingle(roomId, roomPosition, roomDimensions, - connectedRoom, gameScenario, allPositions, allDimensions) { - // CRITICAL: Check if connected room has multiple east connections - const connectedRoomData = gameScenario.rooms[connectedRoom]; - const connectedEastConnections = connectedRoomData?.connections?.east; - - if (Array.isArray(connectedEastConnections) && connectedEastConnections.length > 1) { - // Connected room has multiple east doors - align with the correct one - const indexInArray = connectedEastConnections.indexOf(roomId); - - if (indexInArray >= 0) { - const connectedPos = allPositions[connectedRoom]; - const connectedDim = allDimensions[connectedRoom]; - - // Calculate door Y based on connected room's multi-door spacing - const doorCount = connectedEastConnections.length; - let alignedDoorY; - - if (doorCount === 1) { - alignedDoorY = connectedPos.y + (TILE_SIZE * 2); - } else if (indexInArray === 0) { - alignedDoorY = connectedPos.y + (TILE_SIZE * 2); - } else if (indexInArray === doorCount - 1) { - alignedDoorY = connectedPos.y + connectedDim.heightPx - (TILE_SIZE * 3); - } else { - const firstDoorY = connectedPos.y + (TILE_SIZE * 2); - const lastDoorY = connectedPos.y + connectedDim.heightPx - (TILE_SIZE * 3); - const spacing = (lastDoorY - firstDoorY) / (doorCount - 1); - alignedDoorY = firstDoorY + (spacing * indexInArray); - } - - const doorX = roomPosition.x + TILE_SIZE; - return { x: doorX, y: alignedDoorY }; - } - } - - // Default: place at north corner of west edge +function placeWestDoorSingle(roomId, roomPosition, roomDimensions, connectedRoom) { + // Position along the wall at the west edge const doorX = roomPosition.x + TILE_SIZE; - const doorY = roomPosition.y + (TILE_SIZE * 2); + const doorY = roomPosition.y + (TILE_SIZE * 2); // 2 tiles from top (along the wall) - return { x: doorX, y: doorY }; + return { x: doorX, y: doorY, connectedRoom }; } ```