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
|
module Game.Controller (Controls (..), init, update) where
import Data.Maybe (fromMaybe)
import Game.Utils (isPressed)
import qualified SDL
import Prelude hiding (init)
data Controls = Controls
{ cUp :: Bool,
cDown :: Bool,
cLeft :: Bool,
cRight :: Bool,
cA :: Bool,
cB :: Bool,
cMenu :: Bool
}
deriving (Show)
init :: Controls
init = Controls False False False False False False False
update :: [SDL.EventPayload] -> Controls -> Controls
update events controls =
controls
{ cUp = fromMaybe (cUp controls) $ isPressed SDL.KeycodeUp events,
cDown = fromMaybe (cDown controls) $ isPressed SDL.KeycodeDown events,
cLeft = fromMaybe (cLeft controls) $ isPressed SDL.KeycodeLeft events,
cRight = fromMaybe (cRight controls) $ isPressed SDL.KeycodeRight events,
cA = fromMaybe (cA controls) $ isPressed SDL.KeycodeZ events,
cB = fromMaybe (cB controls) $ isPressed SDL.KeycodeX events,
cMenu = fromMaybe (cMenu controls) $ isPressed SDL.KeycodeReturn events
}
|