Added some initial event handling logic.
authorsabadev <saba@sabadev.xyz>
Sun, 31 Jan 2021 14:56:32 +0000 (09:56 -0500)
committersabadev <saba@sabadev.xyz>
Sun, 31 Jan 2021 14:58:50 +0000 (09:58 -0500)
src/Game.hs

index 9722555..f5d7318 100644 (file)
@@ -1,6 +1,7 @@
 module Game where
 
 import Data.Bifunctor (bimap)
+import Data.Char (toUpper)
 import qualified Terminal.Game as G
 
 data Direction = U | D | L | R deriving (Eq)
@@ -60,7 +61,19 @@ initEnemies :: [Character Enemy]
 initEnemies = mempty
 
 handleEvent :: State -> G.Event -> State
-handleEvent state _ = state
+handleEvent state G.Tick = handleTick state
+handleEvent state (G.KeyPress key) = handleKeyPress state $ toUpper key
+
+handleTick :: State -> State
+handleTick state = state
+
+handleKeyPress :: State -> Char -> State
+handleKeyPress state 'Q' = state { stateIsQuitting = True }
+handleKeyPress state 'W' = state { statePlayer = moveCharacter U (statePlayer state) }
+handleKeyPress state 'S' = state { statePlayer = moveCharacter D (statePlayer state) }
+handleKeyPress state 'A' = state { statePlayer = moveCharacter L (statePlayer state) }
+handleKeyPress state 'D' = state { statePlayer = moveCharacter R (statePlayer state) }
+handleKeyPress state _ = state
 
 render :: State -> G.Plane
 render state = do