fix door coords

This commit is contained in:
Nek0 - 2019-02-17 15:24:49 +01:00
parent 81edf9bcd2
commit c3bf66ba99

View File

@ -118,6 +118,13 @@ loadMapFork ud ad future progress = do
, "Converting to images" , "Converting to images"
))) )))
let !imgmat = convertTileToImg mat let !imgmat = convertTileToImg mat
!doors = Prelude.foldl
(\acc coord@(r, c) -> if mat M.! coord == Door
then V2 r c : acc
else acc
)
[]
((,) <$> [1 .. nrows mat] <*> [1 .. ncols mat])
!exits = Prelude.foldl !exits = Prelude.foldl
(\acc coord@(r, c) -> if imgmat M.! coord == Just ImgEmpty (\acc coord@(r, c) -> if imgmat M.! coord == Just ImgEmpty
then ReachPoint RoomExit (V2 r c) NE 0 : acc then ReachPoint RoomExit (V2 r c) NE 0 : acc
@ -259,7 +266,7 @@ loadMapFork ud ad future progress = do
( p + increment ( p + increment
, "Registering doors into WorldState" , "Registering doors into WorldState"
))) )))
let doors = Prelude.filter ((\t -> t == RoomExit || t == Elevator) . pointType) rps -- let doors = Prelude.filter ((\t -> t == RoomExit || t == Elevator) . pointType) rps
mapM_ (\door -> do mapM_ (\door -> do
let rooms = Prelude.foldl let rooms = Prelude.foldl
(\acc coord -> (\acc coord ->
@ -271,12 +278,8 @@ loadMapFork ud ad future progress = do
) )
[] []
coords coords
[coord] = Prelude.filter
(\(V2 r c) -> (Door ==) $ (mat M.! (r, c)))
coords
graph = Types.connects (head gr) ++ tail gr graph = Types.connects (head gr) ++ tail gr
coords = Prelude.map (pointCoord door +) deltas coords = Prelude.map (door +) deltas
dcoords = Prelude.map (coord +) deltas
deltas = deltas =
[ V2 0 1 [ V2 0 1
, V2 1 0 , V2 1 0
@ -285,7 +288,7 @@ loadMapFork ud ad future progress = do
] ]
wall = Prelude.filter wall = Prelude.filter
(\delta -> (\delta ->
let V2 r c = coord + delta let V2 r c = door + delta
in in
fromMaybe False (isWall <$> imgmat M.! (r, c))) fromMaybe False (isWall <$> imgmat M.! (r, c)))
deltas deltas
@ -294,7 +297,7 @@ loadMapFork ud ad future progress = do
| head wall == V2 1 0 || head wall == V2 (-1) 0 = NE | head wall == V2 1 0 || head wall == V2 (-1) 0 = NE
| otherwise = error ("strange wall: " ++ show wall) | otherwise = error ("strange wall: " ++ show wall)
void $ createEntity $ newEntity void $ createEntity $ newEntity
{ pos = Just (fmap ((+ 0.5) . fromIntegral) coord) { pos = Just (fmap ((+ 0.5) . fromIntegral) door)
, clearanceLvl = Just (maximum $ 0 : Prelude.map clearance (Prelude.map snd rooms)) , clearanceLvl = Just (maximum $ 0 : Prelude.map clearance (Prelude.map snd rooms))
, anim = Just $ AnimState (AnimId AnimDoor0 "shut" orientation) 0 1 , anim = Just $ AnimState (AnimId AnimDoor0 "shut" orientation) 0 1
, obstacle = Just $ case orientation of , obstacle = Just $ case orientation of