mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
fix: Add full tile collision boxes above and below side doors for improved player interaction
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user