let oldPlayer = statePlayer state
let player = moveCharacter (entityDirection oldPlayer) oldPlayer
let box = handleCollision player (stateBox state)
- state { statePlayer = player, stateBox = box, stateScore = stateScore state + 1 }
+ if isOutOfBounds box then state { stateScreen = TitleScreen }
+ else state { statePlayer = player, stateBox = box, stateScore = stateScore state + 1 }
handleTick state = state
handleKeyPress :: State -> Char -> State
handleKeyPress state _ = state
render :: State -> G.Plane
-render state@(State { stateScreen = TitleScreen }) = G.mergePlanes drawBlank $ drawTitle : []
-render state@(State { stateScreen = HelpScreen }) = G.mergePlanes drawBlank $ drawHelp : []
+render state@(State { stateScreen = TitleScreen }) = G.mergePlanes drawBlank $ drawTitle : drawScore state : []
+render state@(State { stateScreen = HelpScreen }) = G.mergePlanes drawBlank $ drawHelp : drawScore state : []
render state@(State { stateScreen = GameScreen }) = do
let playerPlane = drawPlayer $ statePlayer state
let boxPlane = drawBox $ stateBox state
handleCollision (Character { entityCoords = coords, entityDirection = direction }) box
| willCollide direction coords (entityCoords box) = moveCharacter direction box
| otherwise = box
+
+isOutOfBounds :: Character Box -> Bool
+isOutOfBounds (Character { entityCoords = (row, column) }) = row == fst topLeftBoundary || column == snd topLeftBoundary || row == snd bottomRightBoundary || column == fst bottomRightBoundary