Restructuring, #9
This commit is contained in:
parent
2055ef234e
commit
dab6fadad4
41 changed files with 941 additions and 680 deletions
22
lib/RPGEngine/Data/Game.hs
Normal file
22
lib/RPGEngine/Data/Game.hs
Normal file
|
@ -0,0 +1,22 @@
|
|||
module RPGEngine.Data.Game
|
||||
( isLegalMove
|
||||
) where
|
||||
|
||||
import RPGEngine.Data
|
||||
( Player(Player, position),
|
||||
Direction,
|
||||
Physical(Exit, Walkable, Entrance),
|
||||
State(Playing, level),
|
||||
Game(Game, state, player) )
|
||||
import RPGEngine.Data.Level (findAt, directionOffsets)
|
||||
|
||||
------------------------------ Exported ------------------------------
|
||||
|
||||
-- Check if a move is legal by checking what is located at the new position.
|
||||
isLegalMove :: Direction -> Game -> Bool
|
||||
isLegalMove dir g@Game{ state = Playing { level = lvl }, player = p@Player{ position = (x, y) }} = legality
|
||||
where legality = physical `elem` [Walkable, Entrance, Exit]
|
||||
physical = findAt newPos lvl
|
||||
newPos = (x + xD, y + yD)
|
||||
(xD, yD) = directionOffsets dir
|
||||
isLegalMove _ _ = False
|
Reference in a new issue