aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities/Common.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-04-25 22:18:54 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-04-25 22:18:54 +0100
commit1cd60a951b2c2f83b927a6b6961cbd3206bf5316 (patch)
tree59861ba4125ed15ff8711ccd55e4b5a24fd3235c /src/Game/Entities/Common.hs
parenta5ac165b1e9adbdf459ebc9df42edc024389e9b8 (diff)
downloadspace-plat-hs-1cd60a951b2c2f83b927a6b6961cbd3206bf5316.tar.gz
space-plat-hs-1cd60a951b2c2f83b927a6b6961cbd3206bf5316.zip
Added "tracker" enemy
Diffstat (limited to 'src/Game/Entities/Common.hs')
-rw-r--r--src/Game/Entities/Common.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Game/Entities/Common.hs b/src/Game/Entities/Common.hs
index eb84400..8fa7fe3 100644
--- a/src/Game/Entities/Common.hs
+++ b/src/Game/Entities/Common.hs
@@ -3,6 +3,7 @@ module Game.Entities.Common
frameLimit,
collision,
inLine,
+ facingLower,
updateFrame,
updateGravity,
turn,
@@ -54,6 +55,18 @@ inLine playerRef otherHeight other = do
|| (other.dir == DirRight && player.x > other.x)
)
+-- | Check if the entity is facing the player and it is in a lower plarform.
+facingLower :: IORef Entity -> Collision
+facingLower playerRef other = do
+ player <- readIORef playerRef
+ pure $
+ player.typ == TypePlayer
+ && player.gravity == gravityOff
+ && player.y < other.y
+ && ( (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