diff options
Diffstat (limited to 'src/macroknight/systems.hy')
-rw-r--r-- | src/macroknight/systems.hy | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/macroknight/systems.hy b/src/macroknight/systems.hy index 8c1bb9c..f503642 100644 --- a/src/macroknight/systems.hy +++ b/src/macroknight/systems.hy @@ -1,4 +1,4 @@ -(import utils [sub-points Direction]) +(import utils [sub-points distance Direction]) ;; Define systems here (setv GRAVITY 5) @@ -40,14 +40,17 @@ (= entity.type "enemy") ;; If the player is on the tile next to the enemy, attack. (let [player (next (entities-by-type entities ["player"])) - dist (sub-points entity.pos player.pos) - direction (.x-from-move Direction dist)] + delta (sub-points entity.pos player.pos) + dist (distance entity.pos player.pos) + direction (.x-from-move Direction delta)] ;; If facing the player and within reach, attack) (when (and (= direction entity.facing) - (< (get dist 1) 1) ;; Same level - (< (abs (get dist 0)) 2) + (< (get delta 1) 1) ;; Same level + (< (abs (get delta 0)) 2) (not entity.attacking)) - (setv entity.attacking True) - (print "attack") - ) + (.attack entity)) + ;; If not facing the player, turn to face + (when (and (< dist 5) + (!= direction entity.facing)) + (.move entity #((if (< (get delta 0) 0) -1 1) 0))) )) |