diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-03-11 23:17:21 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-03-11 23:17:21 +0000 |
commit | 897bfe0f72ddc80a020a421cbe987b54716e571e (patch) | |
tree | 4fefcc434abf0e0699f40276efefa71a802457b5 /src/Game/Entities | |
parent | edc6b611de752a224082583cd00d19ee6da04c5e (diff) | |
download | space-plat-hs-897bfe0f72ddc80a020a421cbe987b54716e571e.tar.gz space-plat-hs-897bfe0f72ddc80a020a421cbe987b54716e571e.zip |
Exit transition
Diffstat (limited to 'src/Game/Entities')
-rw-r--r-- | src/Game/Entities/Common.hs | 2 | ||||
-rw-r--r-- | src/Game/Entities/Exit.hs | 19 | ||||
-rw-r--r-- | src/Game/Entities/Types.hs | 4 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/Game/Entities/Common.hs b/src/Game/Entities/Common.hs index 2e447f5..69786e5 100644 --- a/src/Game/Entities/Common.hs +++ b/src/Game/Entities/Common.hs @@ -30,7 +30,7 @@ collision :: IORef Entity -> Int -> Collision collision playerRef otherHeight other = do player <- readIORef playerRef pure $ - player.dir /= Dying + player.typ == TypePlayer && player.x + 4 < other.x + 12 && other.x + 4 < player.x + 12 && player.y + otherHeight - 4 < other.y + otherHeight diff --git a/src/Game/Entities/Exit.hs b/src/Game/Entities/Exit.hs index 12f160d..b87c115 100644 --- a/src/Game/Entities/Exit.hs +++ b/src/Game/Entities/Exit.hs @@ -25,15 +25,24 @@ mkExit sprites x y playerCollision = do } updateExit :: Collision -> Entity -> IO Entity -updateExit touchedPlayer e = do - touched <- if e.frame < fullyOpen then pure False else touchedPlayer e - pure $ if touched then e {destroy = True, actions = [ActionExitLevel]} else update +updateExit touchedPlayer e + -- right is the set 0, left set 1 + | e.dir == DirRight = do + touched <- if e.frame < fullyOpen then pure False else touchedPlayer e + pure $ if touched then e {dir = DirLeft, frame = 0, actions = [ActionExitStarted]} else updateLoop + | otherwise = pure updateOnce where fullyOpen :: Int fullyOpen = 7 - update :: Entity - update + updateLoop :: Entity + updateLoop | e.delay > 0 = e {delay = e.delay - 1} | e.frame + 1 < frameLimit e = e {delay = frameDelay, frame = e.frame + 1} | otherwise = e {delay = frameDelay, frame = fullyOpen} + + updateOnce :: Entity + updateOnce + | e.delay > 0 = e {delay = e.delay - 1} + | e.frame + 1 < frameLimit e = e {delay = frameDelay, frame = e.frame + 1} + | otherwise = e {destroy = True, actions = [ActionExitDone]} diff --git a/src/Game/Entities/Types.hs b/src/Game/Entities/Types.hs index 392a86f..4ece6c5 100644 --- a/src/Game/Entities/Types.hs +++ b/src/Game/Entities/Types.hs @@ -14,7 +14,7 @@ import qualified Game.Sprites as S data Dir = DirRight | DirLeft | Dying deriving (Eq) -data Type = TypePlayer | TypePickup | TypeEffect | TypeEnemy +data Type = TypePlayer | TypePickup | TypeEffect | TypeEnemy deriving (Eq) type Collision = Entity -> IO Bool @@ -29,7 +29,7 @@ data Entities = Entities -- | The effect name must match the sprite name in the spritesheet. type EffectName = String -data Action = ActionAddEffect Int Int EffectName | ActionAddBattery Int Int | ActionHitPlayer | ActionExitLevel +data Action = ActionAddEffect Int Int EffectName | ActionAddBattery Int Int | ActionHitPlayer | ActionExitStarted | ActionExitDone data Entity = Entity { typ :: Type, |