Updated direction logic.
authorsabadev <saba@sabadev.xyz>
Sun, 31 Jan 2021 17:48:25 +0000 (12:48 -0500)
committersabadev <saba@sabadev.xyz>
Sun, 31 Jan 2021 18:09:17 +0000 (13:09 -0500)
src/Game.hs

index e579b5f..cf80a28 100644 (file)
@@ -68,11 +68,13 @@ initEnemies :: [Character Enemy]
 initEnemies = mempty
 
 handleEvent :: State -> G.Event -> State
-handleEvent state G.Tick = handleTick state
 handleEvent state (G.KeyPress key) = handleKeyPress state $ toUpper key
+handleEvent state G.Tick = handleTick state
 
 handleTick :: State -> State
-handleTick state = state
+handleTick state = do
+  let player = statePlayer state
+  state { statePlayer = moveCharacter (entityDirection player) player }
 
 handleKeyPress :: State -> Char -> State
 handleKeyPress state 'Q' = state { stateIsQuitting = True }
@@ -103,13 +105,14 @@ bottomRightBoundary :: G.Coords
 bottomRightBoundary = snd boundaries
 
 updateDirection :: Direction -> Character t -> Character t
-updateDirection direction character = character { entityDirection = direction }
+updateDirection direction character@(Character { entityDirection = currentDirection }) = character { entityDirection = if direction == currentDirection then Stop else direction }
 
 moveCharacter :: Direction -> Character t -> Character t
 moveCharacter U character = updatePosition (-1, 0) character
 moveCharacter D character = updatePosition (1, 0) character
 moveCharacter L character = updatePosition (0, -1) character
 moveCharacter R character = updatePosition (0, 1) character
+moveCharacter _ character = character
 
 limitCoords :: G.Coords -> G.Coords
 limitCoords (a, b) = (limitRowCoord a, limitColumnCoord b)