From 2103dc0dcf42fd2489d5f9e4fec46146f7cc9db5 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 4 Feb 2023 21:20:12 +0000 Subject: Initial import --- src/Game/Controller.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/Game/Controller.hs (limited to 'src/Game/Controller.hs') diff --git a/src/Game/Controller.hs b/src/Game/Controller.hs new file mode 100644 index 0000000..3ec7e4c --- /dev/null +++ b/src/Game/Controller.hs @@ -0,0 +1,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 + } -- cgit v1.2.3