From 7a8af18d0e1003c26eb595b5faa71e51da6286a6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 17 Apr 2023 23:41:35 +0100 Subject: Added new shooter enemy --- src/Game/Entities/Common.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/Game/Entities/Common.hs') 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 -- cgit v1.2.3