From 92785d2df84e18953048a6537b71c824a2a4b288 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 19 Feb 2023 20:59:43 +0000 Subject: Make enemies wiggle when the unfreeze --- src/Game/Entities.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Game/Entities.hs b/src/Game/Entities.hs index 10ed1a8..31019ab 100644 --- a/src/Game/Entities.hs +++ b/src/Game/Entities.hs @@ -153,14 +153,22 @@ updateAll es = do render :: SDL.Renderer -> Entities -> IO () render renderer es = do state <- readIORef es.state + -- if the player was hit, make the enemies wiggle before unfreezing + if state.hitDelay == 0 || state.hitDelay > hitDelay `div` 3 + then traverse_ renderOne others + else traverse_ (renderWiggling ((.&.) 2 state.hitDelay)) others -- always render player last - traverse_ renderOne others -- won't draw all the frames if the player was hit if testBit state.hitDelay 2 then pure () else renderOne player where player = head es.entities others = tail es.entities + renderWiggling :: Int -> Entity -> IO () + renderWiggling m e = case e.typ of + TypeEnemy -> renderOne e {x = e.x + m} + _ -> renderOne e + renderOne :: Entity -> IO () renderOne e = S.render renderer e.sprite e.x e.y set e.frame -- cgit v1.2.3