changed visual movement speed to be slower and made diagonal movement with arrow keys work
This commit is contained in:
@@ -20,12 +20,12 @@ export interface GameInputEvents {
|
||||
export class GameInput extends Phaser.Events.EventEmitter {
|
||||
private scene: Phaser.Scene;
|
||||
private cursors: Phaser.Types.Input.Keyboard.CursorKeys;
|
||||
|
||||
|
||||
constructor(scene: Phaser.Scene) {
|
||||
super();
|
||||
this.scene = scene;
|
||||
this.cursors = this.scene.input.keyboard!.createCursorKeys();
|
||||
|
||||
|
||||
this.setupKeyboard();
|
||||
this.setupMouse();
|
||||
}
|
||||
@@ -57,14 +57,14 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
||||
// Logic for "confirm-target" vs "move" happens in Scene for now,
|
||||
// or we can distinguish based on internal state if we moved targeting here.
|
||||
// For now, let's just emit generic events or specific if clear.
|
||||
|
||||
|
||||
// Actually, GameScene has specific logic:
|
||||
// "If targeting active -> Left Click = throw"
|
||||
// "Else -> Left Click = move/attack"
|
||||
|
||||
|
||||
// To keep GameInput "dumb", we just emit the click details.
|
||||
// EXCEPT: Panning logic is computed from pointer movement.
|
||||
|
||||
|
||||
const tx = Math.floor(p.worldX / TILE_SIZE);
|
||||
const ty = Math.floor(p.worldY / TILE_SIZE);
|
||||
this.emit("tile-click", tx, ty, p.button);
|
||||
@@ -80,12 +80,12 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
||||
const isShiftDrag = p.isDown && p.event.shiftKey;
|
||||
|
||||
if (isRightDrag || isMiddleDrag || isShiftDrag) {
|
||||
const { x, y } = p.position;
|
||||
const { x: prevX, y: prevY } = p.prevPosition;
|
||||
|
||||
const dx = (x - prevX); // Zoom factor needs to be handled by receiver or passed here
|
||||
const dy = (y - prevY);
|
||||
this.emit("pan", dx, dy);
|
||||
const { x, y } = p.position;
|
||||
const { x: prevX, y: prevY } = p.prevPosition;
|
||||
|
||||
const dx = (x - prevX); // Zoom factor needs to be handled by receiver or passed here
|
||||
const dy = (y - prevY);
|
||||
this.emit("pan", dx, dy);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -95,7 +95,7 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
||||
// Return simplified cursor state for movement
|
||||
let dx = 0;
|
||||
let dy = 0;
|
||||
|
||||
|
||||
const left = this.cursors.left?.isDown;
|
||||
const right = this.cursors.right?.isDown;
|
||||
const up = this.cursors.up?.isDown;
|
||||
@@ -107,13 +107,19 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
||||
if (down) dy += 1;
|
||||
|
||||
const anyJustDown = Phaser.Input.Keyboard.JustDown(this.cursors.left!) ||
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.right!) ||
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.up!) ||
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.down!);
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.right!) ||
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.up!) ||
|
||||
Phaser.Input.Keyboard.JustDown(this.cursors.down!);
|
||||
|
||||
return { dx, dy, anyJustDown };
|
||||
return {
|
||||
dx, dy, anyJustDown,
|
||||
isLeft: !!left,
|
||||
isRight: !!right,
|
||||
isUp: !!up,
|
||||
isDown: !!down
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public cleanup() {
|
||||
this.removeAllListeners();
|
||||
// Determine is scene specific cleanup is needed for inputs
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user