Move to closest player if it is close
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env python
|
||||
from enum import Enum, auto
|
||||
from math import sqrt
|
||||
from random import randint
|
||||
from typing import List
|
||||
from typing import List, Tuple
|
||||
|
||||
from dungeonbattle.display.texturepack import TexturePack
|
||||
|
||||
@ -172,6 +173,22 @@ class Entity:
|
||||
"""
|
||||
pass
|
||||
|
||||
def distance_squared(self, other: "Entity") -> int:
|
||||
"""
|
||||
Get the square of the distance to another entity.
|
||||
Useful to check distances since square root takes time.
|
||||
"""
|
||||
return (self.y - other.y) ** 2 + (self.x - other.x) ** 2
|
||||
|
||||
def distance(self, other: "Entity") -> float:
|
||||
"""
|
||||
Get the cartesian distance to another entity.
|
||||
"""
|
||||
return sqrt(self.distance_squared(other))
|
||||
|
||||
def vector(self, other: "Entity") -> Tuple[int, int]:
|
||||
return other.y - self.y, other.x - self.x
|
||||
|
||||
|
||||
class FightingEntity(Entity):
|
||||
maxhealth: int
|
||||
|
Reference in New Issue
Block a user