Allow melee attacking diagonally as well

This commit is contained in:
Peter Stockings
2026-01-06 10:53:13 +11:00
parent 0263495d0b
commit a9779348e9
3 changed files with 149 additions and 22 deletions

View File

@@ -309,7 +309,6 @@ export function decideEnemyAction(w: World, enemy: CombatantActor, player: Comba
const canSee = canEnemySeePlayer(w, enemy, player);
const dx = player.pos.x - enemy.pos.x;
const dy = player.pos.y - enemy.pos.y;
const dist = Math.abs(dx) + Math.abs(dy);
// State transitions
let justAlerted = false;
@@ -369,8 +368,9 @@ export function decideEnemyAction(w: World, enemy: CombatantActor, player: Comba
const targetDx = targetPos.x - enemy.pos.x;
const targetDy = targetPos.y - enemy.pos.y;
// If adjacent to player, attack
if (dist === 1 && canSee) {
// If adjacent or diagonal to player, attack
const chebyshevDist = Math.max(Math.abs(dx), Math.abs(dy));
if (chebyshevDist === 1 && canSee) {
return { action: { type: "attack", targetId: player.id }, justAlerted };
}