From 897bfe0f72ddc80a020a421cbe987b54716e571e Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 11 Mar 2023 23:17:21 +0000 Subject: Exit transition --- src/Game/Entities.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/Game/Entities.hs') 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 -- cgit v1.2.3