aboutsummaryrefslogtreecommitdiff
path: root/src/Game
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-25 13:50:04 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-25 13:50:04 +0000
commit2f40109ab69892c7b7812fdbba3a83dc3ca96193 (patch)
treedb3a61adae19487c15f5977befd918a5fb213c9b /src/Game
parente066422b950a06873efb6a884b47155c867b7acf (diff)
downloadspace-plat-hs-2f40109ab69892c7b7812fdbba3a83dc3ca96193.tar.gz
space-plat-hs-2f40109ab69892c7b7812fdbba3a83dc3ca96193.zip
Game over sequence WIP
Diffstat (limited to 'src/Game')
-rw-r--r--src/Game/Entities/Common.hs5
-rw-r--r--src/Game/Entities/Const.hs3
-rw-r--r--src/Game/State.hs3
3 files changed, 9 insertions, 2 deletions
diff --git a/src/Game/Entities/Common.hs b/src/Game/Entities/Common.hs
index 2a0c6f1..251dbb4 100644
--- a/src/Game/Entities/Common.hs
+++ b/src/Game/Entities/Common.hs
@@ -43,7 +43,10 @@ hitPlayer stateRef =
stateRef $~ updatePlayerHit
where
updatePlayerHit :: GS.State -> GS.State
- updatePlayerHit s = s {GS.lives = s.lives - 1, GS.hitDelay = hitDelay}
+ updatePlayerHit s
+ -- if we run out of lives, trigger the game over
+ | s.lives == 1 = s {GS.lives = 0, GS.gameOverDelay = gameOverDelay}
+ | otherwise = s {GS.lives = s.lives - 1, GS.hitDelay = hitDelay}
-- | Update game state to reflect that the player picked up a battery.
collectedBattery :: IORef GS.State -> IO ()
diff --git a/src/Game/Entities/Const.hs b/src/Game/Entities/Const.hs
index 4855e24..a24c304 100644
--- a/src/Game/Entities/Const.hs
+++ b/src/Game/Entities/Const.hs
@@ -3,6 +3,9 @@ module Game.Entities.Const where
hitDelay :: Int
hitDelay = 96
+gameOverDelay :: Int
+gameOverDelay = 96
+
frameDelay :: Int
frameDelay = 6
diff --git a/src/Game/State.hs b/src/Game/State.hs
index d943ac0..f8b5721 100644
--- a/src/Game/State.hs
+++ b/src/Game/State.hs
@@ -5,5 +5,6 @@ data State = State
totalBatteries :: Int,
lives :: Int,
totalLives :: Int,
- hitDelay :: Int
+ hitDelay :: Int,
+ gameOverDelay :: Int
}