#4 Pick up items

This commit is contained in:
Tibo De Peuter 2022-12-23 10:21:56 +01:00
parent 72b460788d
commit b108b2ed65
2 changed files with 23 additions and 4 deletions

View file

@ -37,6 +37,15 @@ hasAt pos level = match firstItem firstEntity
firstItem = find ((== pos) . getICoord) $ items level
getICoord i = (itemX i, itemY i)
getWithId :: String -> Level -> Maybe (Either Item Entity)
getWithId id level = match firstItem firstEntity
where match :: Maybe Item -> Maybe Entity -> Maybe (Either Item Entity)
match (Just a) _ = Just $ Left a
match _ (Just a) = Just $ Right a
match _ _ = Nothing
firstEntity = find ((== id) . entityId) $ entities level
firstItem = find ((== id) . itemId) $ items level
directionOffsets :: Direction -> (X, Y)
directionOffsets North = ( 0, 1)
directionOffsets East = ( 1, 0)