From b3e0ace3ca198cacd8d77c6ca0f2c457826dee63 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 26 Feb 2023 00:06:40 +0000 Subject: Revisited the game over sequence --- src/Game/Entities/Common.hs | 5 ++++- src/Game/Entities/Player.hs | 18 ++++++++++-------- src/Game/Entities/Types.hs | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/Game/Entities') diff --git a/src/Game/Entities/Common.hs b/src/Game/Entities/Common.hs index 251dbb4..ca5eb78 100644 --- a/src/Game/Entities/Common.hs +++ b/src/Game/Entities/Common.hs @@ -20,6 +20,8 @@ import SDL (($~)) toSpriteSet :: Dir -> Int toSpriteSet DirRight = 0 toSpriteSet DirLeft = 1 +-- not really a direction +toSpriteSet Dying = 2 -- | Return the number of frames available on the entity's sprite for current direction. frameLimit :: Entity -> Int @@ -32,7 +34,8 @@ collision :: IORef Entity -> Int -> Collision collision playerRef otherHeight other = do player <- readIORef playerRef pure $ - player.x + 4 < other.x + 12 + player.dir /= Dying + && player.x + 4 < other.x + 12 && other.x + 4 < player.x + 12 && player.y + otherHeight - 4 < other.y + otherHeight && other.y + 4 < player.y + 24 diff --git a/src/Game/Entities/Player.hs b/src/Game/Entities/Player.hs index 78da30e..f0a526c 100644 --- a/src/Game/Entities/Player.hs +++ b/src/Game/Entities/Player.hs @@ -58,11 +58,13 @@ updateVertical isBlocked jump down e | otherwise = e updatePlayer :: IORef C.Controls -> IsBlocked -> Entity -> IO Entity -updatePlayer controls isBlocked e = do - ctl <- readIORef controls - pure $ - updateGravity isBlocked $ - updateVertical isBlocked ctl.a ctl.down $ - updateHorizontal isBlocked ctl.left ctl.right $ - -- left or right, but not both (keyboard) - updateFrame ((ctl.left || ctl.right) && (ctl.left /= ctl.right)) e +updatePlayer controls isBlocked e + | e.dir /= Dying = do + ctl <- readIORef controls + pure $ + updateGravity isBlocked $ + updateVertical isBlocked ctl.a ctl.down $ + updateHorizontal isBlocked ctl.left ctl.right $ + -- left or right, but not both (keyboard) + updateFrame ((ctl.left || ctl.right) && (ctl.left /= ctl.right)) e + | otherwise = pure $ updateGravity (\_ _ -> False) e diff --git a/src/Game/Entities/Types.hs b/src/Game/Entities/Types.hs index ed609d3..a50ab2d 100644 --- a/src/Game/Entities/Types.hs +++ b/src/Game/Entities/Types.hs @@ -13,7 +13,7 @@ import Data.IORef import qualified Game.Sprites as S import qualified Game.State as GS -data Dir = DirRight | DirLeft deriving (Eq) +data Dir = DirRight | DirLeft | Dying deriving (Eq) data Type = TypePlayer | TypePickup | TypeEffect | TypeEnemy -- cgit v1.2.3