x = $this->destX = $homeX; $this->y = $this->destY = $homeY; $this->hp = $this->maxHp = (float)$def['hp']; } public function isAlive(): bool { return $this->hp > 0; } public function isWalking(): bool { return hypot($this->destX - $this->x, $this->destY - $this->y) > 1; } public function isFighting(): bool { return $this->target !== null && $this->isAlive() && !$this->isWalking() && hypot($this->target->x - $this->x, $this->target->y - $this->y) <= 10; } public function skillReady(): bool { return $this->isAlive() && $this->skillTimer <= 0; } /** Walks towards ($x, $y) at its speed. */ public function walk(float $x, float $y, float $h): void { $dx = $x - $this->x; $dy = $y - $this->y; $d = hypot($dx, $dy); if ($d < 0.5) { return; } $move = min($d, (float)$this->def['speed'] * $h); $this->x += $dx / $d * $move; $this->y += $dy / $d * $move; if (abs($dx) > 0.5) { $this->facingLeft = $dx < 0; } $this->age += $h; } }