changed visual movement speed to be slower and made diagonal movement with arrow keys work

This commit is contained in:
2026-01-28 18:59:35 +11:00
parent f01d8de15c
commit 80e82f68a0
6 changed files with 185 additions and 142 deletions

View File

@@ -12,19 +12,19 @@ import * as ROT from "rot-js";
* - You cannot path TO an unseen target tile.
*/
export function findPathAStar(
w: World,
seen: Uint8Array,
start: Vec2,
end: Vec2,
w: World,
seen: Uint8Array,
start: Vec2,
end: Vec2,
options: { ignoreBlockedTarget?: boolean; ignoreSeen?: boolean; accessor?: EntityAccessor } = {}
): Vec2[] {
// Validate target
if (!inBounds(w, end.x, end.y)) return [];
if (isWall(w, end.x, end.y)) return [];
// Check if target is blocked (unless ignoring)
if (!options.ignoreBlockedTarget && isBlocked(w, end.x, end.y, options.accessor)) return [];
// Check if target is unseen (unless ignoring)
if (!options.ignoreSeen && seen[idx(w, end.x, end.y)] !== 1) return [];
@@ -36,7 +36,7 @@ export function findPathAStar(
// Start position is always passable
if (x === start.x && y === start.y) return true;
// Target position is passable (we already validated it above)
if (x === end.x && y === end.y) return true;
@@ -49,11 +49,11 @@ export function findPathAStar(
return true;
};
// Use rot-js A* pathfinding with 4-directional topology
const astar = new ROT.Path.AStar(end.x, end.y, passableCallback, { topology: 4 });
// Use rot-js A* pathfinding with 8-directional topology
const astar = new ROT.Path.AStar(end.x, end.y, passableCallback, { topology: 8 });
const path: Vec2[] = [];
// Compute path from start to end
astar.compute(start.x, start.y, (x: number, y: number) => {
path.push({ x, y });