parent
de02c7113f
commit
fb4bc5bb36
12 changed files with 158 additions and 9 deletions
19
lib/RPGEngine/Input/Player.hs
Normal file
19
lib/RPGEngine/Input/Player.hs
Normal file
|
@ -0,0 +1,19 @@
|
|||
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)
|
Reference in a new issue