mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-20 13:50:46 +00:00
feat: Implement door walkability marking in pathfinding for unlocked/opened doors
This commit is contained in:
@@ -535,6 +535,16 @@ export function createDoorSpritesForRoom(roomId, position) {
|
||||
doorSprite.interactionZone = zone;
|
||||
doorSprites.push(doorSprite);
|
||||
|
||||
// If door starts unlocked, mark it as walkable in pathfinding
|
||||
if (!doorSprite.doorProperties.locked && window.pathfindingManager) {
|
||||
window.pathfindingManager.markDoorWalkable(
|
||||
roomId,
|
||||
doorSprite.doorProperties.worldX,
|
||||
doorSprite.doorProperties.worldY,
|
||||
doorSprite.doorProperties.direction
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Created door sprite for ${roomId} -> ${connectedRoom} (${direction}) at (${doorX}, ${doorY})`);
|
||||
});
|
||||
|
||||
@@ -608,6 +618,31 @@ function openDoor(doorSprite) {
|
||||
// Wait for game scene to be ready before proceeding
|
||||
// This prevents crashes when called immediately after minigame cleanup
|
||||
const finishOpeningDoor = () => {
|
||||
// Update pathfinding grid to mark door tiles as walkable
|
||||
if (window.pathfindingManager) {
|
||||
// Mark door walkable in the current room
|
||||
window.pathfindingManager.markDoorWalkable(
|
||||
props.roomId,
|
||||
props.worldX,
|
||||
props.worldY,
|
||||
props.direction
|
||||
);
|
||||
|
||||
// Also mark door walkable in the connected room (opposite direction)
|
||||
const oppositeDirections = {
|
||||
'north': 'south',
|
||||
'south': 'north',
|
||||
'east': 'west',
|
||||
'west': 'east'
|
||||
};
|
||||
window.pathfindingManager.markDoorWalkable(
|
||||
props.connectedRoom,
|
||||
props.worldX,
|
||||
props.worldY,
|
||||
oppositeDirections[props.direction]
|
||||
);
|
||||
}
|
||||
|
||||
// Load the connected room if it doesn't exist
|
||||
// Use window.rooms to ensure we see the latest state
|
||||
const needsLoading = !window.rooms || !window.rooms[props.connectedRoom];
|
||||
|
||||
@@ -454,6 +454,64 @@ export class NPCPathfindingManager {
|
||||
getBounds(roomId) {
|
||||
return this.roomBounds.get(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark door tiles as walkable in the pathfinding grid
|
||||
* Called when a door is unlocked/opened
|
||||
*
|
||||
* @param {string} roomId - Room containing the door
|
||||
* @param {number} worldX - World X position of door
|
||||
* @param {number} worldY - World Y position of door
|
||||
* @param {string} direction - Door direction (north/south/east/west)
|
||||
*/
|
||||
markDoorWalkable(roomId, worldX, worldY, direction) {
|
||||
const grid = this.grids.get(roomId);
|
||||
const pathfinder = this.pathfinders.get(roomId);
|
||||
const bounds = this.roomBounds.get(roomId);
|
||||
|
||||
if (!grid || !pathfinder || !bounds) {
|
||||
console.warn(`⚠️ Cannot update door pathfinding - room ${roomId} not initialized`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert world coordinates to tile coordinates
|
||||
const tileX = Math.floor((worldX - bounds.worldX) / TILE_SIZE);
|
||||
const tileY = Math.floor((worldY - bounds.worldY) / TILE_SIZE);
|
||||
|
||||
// Mark door tiles as walkable (typically 2 tiles for a door)
|
||||
const tilesToMark = [];
|
||||
|
||||
switch (direction) {
|
||||
case 'north':
|
||||
case 'south':
|
||||
// Horizontal door - 2 tiles wide
|
||||
tilesToMark.push({ x: tileX, y: tileY });
|
||||
tilesToMark.push({ x: tileX + 1, y: tileY });
|
||||
break;
|
||||
case 'east':
|
||||
case 'west':
|
||||
// Vertical door - 2 tiles high
|
||||
tilesToMark.push({ x: tileX, y: tileY });
|
||||
tilesToMark.push({ x: tileX, y: tileY + 1 });
|
||||
break;
|
||||
}
|
||||
|
||||
let markedCount = 0;
|
||||
tilesToMark.forEach(tile => {
|
||||
if (tile.y >= 0 && tile.y < grid.length &&
|
||||
tile.x >= 0 && tile.x < grid[0].length) {
|
||||
if (grid[tile.y][tile.x] === 1) {
|
||||
grid[tile.y][tile.x] = 0; // Mark as walkable
|
||||
markedCount++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Update the pathfinder with the new grid
|
||||
pathfinder.setGrid(grid);
|
||||
|
||||
console.log(`✅ Marked ${markedCount} door tiles as walkable in ${roomId} at (${tileX}, ${tileY}) direction: ${direction}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Export as global for easy access
|
||||
|
||||
Reference in New Issue
Block a user