19 lines
535 B
Haskell
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)
|