#3 Restrict player going places
This commit is contained in:
parent
5c8cee8104
commit
0786a41006
6 changed files with 78 additions and 21 deletions
27
lib/RPGEngine/Input/Level.hs
Normal file
27
lib/RPGEngine/Input/Level.hs
Normal file
|
@ -0,0 +1,27 @@
|
|||
module RPGEngine.Input.Level
|
||||
( putCoords
|
||||
, findFirst
|
||||
, whatIsAt
|
||||
) where
|
||||
import RPGEngine.Data (Level (..), Y, X, Physical(..))
|
||||
|
||||
-- Map all Physicals onto coordinates
|
||||
putCoords :: Level -> [(X, Y, Physical)]
|
||||
putCoords l@Level{ layout = lay } = concatMap (\(a, bs) -> map (\(b, c) -> (b, a, c)) bs) numberedList
|
||||
where numberedStrips = zip [0::Int .. ] lay
|
||||
numberedList = map (\(x, strip) -> (x, zip [0::Int ..] strip)) numberedStrips
|
||||
|
||||
-- Find first position of a Physical
|
||||
-- Graceful exit by giving Nothing if there is nothing found.
|
||||
findFirst :: Level -> Physical -> Maybe (X, Y)
|
||||
findFirst l@Level{ coordlayout = lay } physical = try
|
||||
where matches = filter (\(x, y, v) -> v == physical) lay
|
||||
try | not (null matches) = Just $ (\(x, y, _) -> (x, y)) $ head matches
|
||||
| otherwise = Nothing
|
||||
|
||||
-- What is located at a given position in the level?
|
||||
whatIsAt :: (X, Y) -> Level -> Physical
|
||||
whatIsAt pos lvl@Level{ coordlayout = lay } = try
|
||||
where matches = map (\(_, _, v) -> v) $ filter (\(x, y, v) -> (x, y) == pos) lay
|
||||
try | not (null matches) = head matches
|
||||
| otherwise = Void
|
Reference in a new issue