From 381c89c0209baf68957fcc347be54bfea34d1cab Mon Sep 17 00:00:00 2001 From: sabadev Date: Sun, 31 Jan 2021 19:18:16 -0500 Subject: [PATCH] Updated movement for player to make it easier to control the box. --- src/Game.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Game.hs b/src/Game.hs index 96fe29b..c5f7bad 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -43,7 +43,7 @@ drawTitle :: (G.Coords, G.Plane) drawTitle = (bimap (flip (-) 3) (flip (-) 6) centreCoords, G.stringPlane "==AVOIDANCE==\n\n\nMove: WASD\nHelp: H\nPlay: P\nQuit: Q") drawHelp :: (G.Coords, G.Plane) -drawHelp = (topLeftBoundary, G.textBox "Use W, A, S, and D to move up, left, down, and right respectively.\nPress a direction key to start moving in that direction, and then press the same key again to stop.\nPush the box around the screen, making sure that it is not pushed off the edge.\nBox thieves will appear sporadically to steal the box.\nYour objective is to keep the box on-screen for as long as possible.\n\n P: Player\n O: Box\n X: Box Thief" (fst bottomRightBoundary) (snd bottomRightBoundary)) +drawHelp = (topLeftBoundary, G.textBox "Use W, A, S, and D to move up, left, down, and right respectively.\nPush the box around the screen, making sure that it is not pushed off the edge.\nBox thieves will appear sporadically to steal the box.\nYour objective is to keep the box on-screen for as long as possible.\n\n P: Player\n O: Box\n X: Box Thief" (fst bottomRightBoundary) (snd bottomRightBoundary)) drawBlank :: G.Plane drawBlank = G.blankPlane (fst bottomRightBoundary) (snd bottomRightBoundary) @@ -105,7 +105,7 @@ handleTick state@(State { stateScreen = GameScreen }) = do let box = handleCollision player $ handleCollisions (stateEnemy stateAfterEnemies) (stateBox stateAfterEnemies) let newScore = stateScore stateAfterEnemies + 1 if isOutOfBounds box then stateAfterEnemies { stateScreen = TitleScreen } - else stateAfterEnemies { statePlayer = player, stateBox = box, stateScore = newScore, stateDifficulty = div newScore 200 + 1 } + else stateAfterEnemies { statePlayer = resetDirection player, stateBox = box, stateScore = newScore, stateDifficulty = div newScore 200 + 1 } handleTick state = state handleEnemies :: State -> State @@ -170,8 +170,11 @@ topLeftBoundary = fst boundaries bottomRightBoundary :: G.Coords bottomRightBoundary = snd boundaries -updateDirection :: Direction -> Character t -> Character t -updateDirection direction character@(Character { entityDirection = currentDirection }) = character { entityDirection = if direction == currentDirection then Stop else direction } +resetDirection :: Character Player -> Character Player +resetDirection character = character { entityDirection = Stop } + +updateDirection :: Direction -> Character Player -> Character Player +updateDirection direction character = character { entityDirection = direction } moveCharacter :: Direction -> Character t -> Character t moveCharacter U character = updatePosition (-1, 0) character -- 2.20.1