This repository has been archived on 2023-06-24. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2022FuncProg-project3-RPGEn.../lib/RPGEngine/Input/Player.hs

19 lines
535 B
Haskell

module RPGEngine.Input.Player
( movePlayer
) where
import RPGEngine.Data (Game(..), Direction(..), Player(..), X, Y)
movePlayer :: Direction -> Game -> Game
movePlayer dir g@Game{ player = p@Player{ coord = (x, y) }} = newGame
where newGame = g{ player = newPlayer }
newPlayer = p{ coord = newCoord }
newCoord = (x + xD, y + yD)
(xD, yD) = diffs dir
diffs :: Direction -> (X, Y)
diffs North = (0, 1)
diffs East = (1, 0)
diffs South = (0, -1)
diffs West = (-1, 0)
diffs Center = (0, 0)