aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Entities.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-11 23:17:21 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-03-11 23:17:21 +0000
commit897bfe0f72ddc80a020a421cbe987b54716e571e (patch)
tree4fefcc434abf0e0699f40276efefa71a802457b5 /src/Game/Entities.hs
parentedc6b611de752a224082583cd00d19ee6da04c5e (diff)
downloadspace-plat-hs-897bfe0f72ddc80a020a421cbe987b54716e571e.tar.gz
space-plat-hs-897bfe0f72ddc80a020a421cbe987b54716e571e.zip
Exit transition
Diffstat (limited to 'src/Game/Entities.hs')
-rw-r--r--src/Game/Entities.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs
index b53e4e3..8a939f4 100644
--- a/src/Game/Entities.hs
+++ b/src/Game/Entities.hs
@@ -60,8 +60,8 @@ addExit es x y = do
updateAll :: Entities -> GS.State -> IO (Entities, GS.State)
updateAll es state = do
- -- update the player first (including the reference)
- updatedPlayer <- player.update player
+ -- update the player first (including the reference), unless the level is completed
+ updatedPlayer <- if state.levelCompleted /= GS.ExitOff then pure player else player.update player
void $ writeIORef es.player updatedPlayer
-- then the other entities
updated <- (updatedPlayer :) <$> traverse (updateFilter $ state.hitDelay > 0) others
@@ -91,14 +91,21 @@ updateAll es state = do
if s.lives == 1
then
( s {GS.lives = 0, GS.gameOverDelay = gameOverDelay},
- (head ents) {dir = Dying, gravity = gravityUp, frame = 0} : tail ents
+ -- the player is not in the action, changing then type disables collision detection
+ (head ents) {typ = TypeEffect, dir = Dying, gravity = gravityUp, frame = 0} : tail ents
)
else
( s {GS.lives = s.lives - 1, GS.hitDelay = hitDelay},
ents
)
processActions s' ents' t
- ActionExitLevel -> processActions s {GS.levelCompleted = True} ents t
+ ActionExitStarted ->
+ processActions
+ s {GS.levelCompleted = GS.ExitStarted}
+ -- the player is not in the action, changing the type disables collision detection
+ ((head ents) {typ = TypeEffect} : tail ents)
+ t
+ ActionExitDone -> processActions s {GS.levelCompleted = GS.ExitDone} ents t
processActions s ents [] = pure (s, ents)
-- Update entities skipping enemies if the player was hit
@@ -134,7 +141,8 @@ render renderer es state = do
else traverse_ (renderWiggling ((.&.) 2 state.hitDelay)) others
-- always render player last
-- won't draw all the frames if the player was hit
- if testBit state.hitDelay 2 then pure () else renderOne player
+ -- or we are exiting the level
+ if testBit state.hitDelay 2 || state.levelCompleted /= GS.ExitOff then pure () else renderOne player
where
player = head es.entities
others = tail es.entities