diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-04-17 23:41:35 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-04-17 23:41:35 +0100 |
commit | 7a8af18d0e1003c26eb595b5faa71e51da6286a6 (patch) | |
tree | d94ea6897570e12d9c044c40e82e9c05921ba64d /src/Game/Entities/Common.hs | |
parent | d333eca8c0761e39781af0711a54044cd5ea3c10 (diff) | |
download | space-plat-hs-7a8af18d0e1003c26eb595b5faa71e51da6286a6.tar.gz space-plat-hs-7a8af18d0e1003c26eb595b5faa71e51da6286a6.zip |
Added new shooter enemy
Diffstat (limited to 'src/Game/Entities/Common.hs')
-rw-r--r-- | src/Game/Entities/Common.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Game/Entities/Common.hs b/src/Game/Entities/Common.hs index 82e790e..661fe07 100644 --- a/src/Game/Entities/Common.hs +++ b/src/Game/Entities/Common.hs @@ -2,6 +2,7 @@ module Game.Entities.Common ( toSpriteSet, frameLimit, collision, + inLine, updateFrame, updateGravity, ) @@ -34,6 +35,19 @@ collision playerRef otherHeight other = do && player.y + otherHeight - 4 < other.y + otherHeight && other.y + 4 < player.y + 24 +-- | Check if the player is in line with the entity and the entity is facing the player. +inLine :: IORef Entity -> Int -> Collision +inLine playerRef otherHeight other = do + player <- readIORef playerRef + pure $ + player.typ == TypePlayer + && player.y + otherHeight - 4 < other.y + otherHeight + && other.y + 4 < player.y + 24 + -- XXX: adjust perhaps? so the enemies don't shoot too close to the player + && ( (other.dir == DirLeft && player.x < other.x) + || (other.dir == DirRight && player.x > other.x) + ) + -- | Update frame animation for entities that have direction. updateFrame :: Bool -> Entity -> Entity updateFrame updated e |