From: sabadev Date: Sun, 31 Jan 2021 17:48:25 +0000 (-0500) Subject: Updated direction logic. X-Git-Url: http://sabadev.xyz:4321/?a=commitdiff_plain;h=09e0434e49b681c1915bccd8ae6084dbb3ee5184;p=avoidance.git Updated direction logic. --- diff --git a/src/Game.hs b/src/Game.hs index e579b5f..cf80a28 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -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)