aboutsummaryrefslogtreecommitdiff
path: root/src/Game/State.hs
blob: 37732685d867d6a2af5db2117c569d0bb68a0f84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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,
    totalBatteries :: Int,
    lives :: Int,
    totalLives :: Int,
    hitDelay :: Int,
    gameOverDelay :: Int,
    exit :: Bool,
    lastBattery :: (Int, Int),
    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
    }