Move to closest player if it is close

This commit is contained in:
Yohann D'ANELLO
2020-11-10 22:59:02 +01:00
parent 12ee436f4d
commit f9f02b6621
3 changed files with 48 additions and 5 deletions

View File

@ -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