Allow melee attacking diagonally as well
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user