From edc6b611de752a224082583cd00d19ee6da04c5e Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 11 Mar 2023 22:21:06 +0000 Subject: Tidy up, state functions to state module --- src/Game/State.hs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/Game/State.hs') diff --git a/src/Game/State.hs b/src/Game/State.hs index e05fb61..3773268 100644 --- a/src/Game/State.hs +++ b/src/Game/State.hs @@ -1,4 +1,10 @@ -module Game.State (State (..)) where +module Game.State (State (..), initialState, levelState, maxLives) where + +import Game.Entities.Const (hitDelay) +import qualified Game.Map as M + +maxLives :: Int +maxLives = 4 data State = State { batteries :: Int, @@ -12,3 +18,32 @@ data State = State levelCompleted :: Bool, currentLevel :: Int } + +initialState :: M.Map -> State +initialState m = + State + { batteries = 0, + totalBatteries = M.totalBatteries m, + lives = maxLives, + totalLives = maxLives, + hitDelay = hitDelay, + gameOverDelay = 0, + exit = False, + -- doesn't matter where + lastBattery = (0, 0), + levelCompleted = False, + currentLevel = 0 + } + +levelState :: State -> M.Map -> State +levelState s m = + s + { batteries = 0, + totalBatteries = M.totalBatteries m, + hitDelay = hitDelay, + gameOverDelay = 0, + exit = False, + -- doesn't matter where + lastBattery = (0, 0), + levelCompleted = False + } -- cgit v1.2.3