diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-02-19 20:59:43 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-02-19 20:59:43 +0000 |
commit | 92785d2df84e18953048a6537b71c824a2a4b288 (patch) | |
tree | 8d53d486b3e3dc48c7fbf0662208a8a64c624a2a /src/Game/Entities.hs | |
parent | 93aedcb24f6646ebcbca105267dc07f369fc6391 (diff) | |
download | space-plat-hs-92785d2df84e18953048a6537b71c824a2a4b288.tar.gz space-plat-hs-92785d2df84e18953048a6537b71c824a2a4b288.zip |
Make enemies wiggle when the unfreeze
Diffstat (limited to 'src/Game/Entities.hs')
-rw-r--r-- | src/Game/Entities.hs | 10 |
1 files changed, 9 insertions, 1 deletions
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 |