From b2fd57548f4293a5bf19d6115ea34e25b86734ce Mon Sep 17 00:00:00 2001 From: sabadev Date: Sun, 31 Jan 2021 09:56:32 -0500 Subject: [PATCH] Added some initial event handling logic. --- src/Game.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Game.hs b/src/Game.hs index 9722555..f5d7318 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -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 -- 2.20.1