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/Data/Game.hs
2022-12-21 23:30:59 +01:00

22 lines
No EOL
788 B
Haskell

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