don't draw NPCs outside of visible area
This commit is contained in:
parent
b6deacbf14
commit
755350ba9f
3 changed files with 28 additions and 8 deletions
23
src/NPC.hs
23
src/NPC.hs
|
@ -30,11 +30,22 @@ drawNPCs
|
|||
-> Double
|
||||
-> Int
|
||||
-> Int
|
||||
-> Maybe ImgId
|
||||
-> Affection UserData ()
|
||||
drawNPCs ctx npcposs prow pcol row col = do
|
||||
drawNPCs ctx npcposs prow pcol row col img = do
|
||||
ud <- getAffection
|
||||
let fnpcposs = filter
|
||||
(\(V2 nr nc) -> floor nr == row && floor nc == col)
|
||||
(\(V2 nr nc) ->
|
||||
let x = realToFrac $ 640 + ((nc - pcol) + (nr - prow)) * 32
|
||||
y = realToFrac $ 360 + ((nr - prow) - (nc - pcol)) * 16
|
||||
in ((realToFrac x > -tileWidth && realToFrac y > -tileHeight) &&
|
||||
(realToFrac x < 1280 && realToFrac (y - (74 - realToFrac tileHeight)) < 720)) &&
|
||||
((all (\m -> prow > (fromIntegral (floor prow :: Int)) + m) minrs &&
|
||||
all (\m -> pcol < (fromIntegral (floor pcol :: Int)) + m) mincs) ||
|
||||
(all (\m -> prow > (fromIntegral (floor prow :: Int)) + m) minrs &&
|
||||
all (\m -> pcol < (fromIntegral (floor pcol :: Int)) + m) maxcs)) &&
|
||||
(floor nr == row && floor nc == col)
|
||||
)
|
||||
npcposs
|
||||
liftIO $ mapM_
|
||||
(\(V2 nr nc) -> do
|
||||
|
@ -47,6 +58,14 @@ drawNPCs ctx npcposs prow pcol row col = do
|
|||
fill ctx
|
||||
)
|
||||
fnpcposs
|
||||
where
|
||||
tileWidth = 64 :: Double
|
||||
tileHeight = 32 :: Double
|
||||
mb = imgObstacle img
|
||||
minrs = Prelude.map (fst . matmin) mb
|
||||
maxrs = Prelude.map (fst . matmax) mb
|
||||
mincs = Prelude.map (snd . matmin) mb
|
||||
maxcs = Prelude.map (snd . matmax) mb
|
||||
|
||||
placeNPCs
|
||||
:: M.Matrix (Maybe ImgId)
|
||||
|
|
|
@ -161,7 +161,7 @@ drawMap = do
|
|||
(\(j, t) -> do
|
||||
liftIO $ drawTile
|
||||
(assetImages ud) ctx pr pc i j t
|
||||
drawNPCs ctx npcposs pr pc i j
|
||||
drawNPCs ctx npcposs pr pc i j t
|
||||
)
|
||||
(reverse $ zip [1..] ls))
|
||||
(zip [1..] (toLists mat))
|
||||
|
|
11
src/Util.hs
11
src/Util.hs
|
@ -133,7 +133,7 @@ astarAppl imgmat target start = aStar
|
|||
|
||||
naviGraph :: Matrix (Maybe ImgId) -> V2 Int -> HS.HashSet (V2 Int)
|
||||
naviGraph imgmat (V2 r c) =
|
||||
let list =
|
||||
let list1 =
|
||||
foldl
|
||||
(\acc (or, oc) ->
|
||||
if null (imgObstacle $ imgmat M.! (r + or, c + oc))
|
||||
|
@ -142,16 +142,17 @@ naviGraph imgmat (V2 r c) =
|
|||
)
|
||||
[]
|
||||
[(0, 1), (0, -1), (1, 0), (-1, 0)]
|
||||
++
|
||||
list2 =
|
||||
foldl
|
||||
(\acc (or, oc) ->
|
||||
if all null
|
||||
if null (imgObstacle $ imgmat M.! (r + or, c + oc))
|
||||
&& any null
|
||||
(map
|
||||
(\(oor, ooc) -> imgObstacle $ imgmat M.! (r + oor, c + ooc))
|
||||
[(0, oc), (or, 0), (or, oc)])
|
||||
[(0, oc), (or, 0)])
|
||||
then V2 (r + or) (c + oc): acc
|
||||
else acc
|
||||
)
|
||||
[]
|
||||
[(-1, -1), (-1, 1), (1, -1), (1, 1)]
|
||||
in HS.fromList list
|
||||
in HS.fromList (list1 ++ list2)
|
||||
|
|
Loading…
Reference in a new issue