only draw visible tiles
This commit is contained in:
parent
a05799cc9f
commit
366b79ecef
2 changed files with 30 additions and 27 deletions
|
@ -84,7 +84,7 @@ placeNPCs imgmat tilemat rp gr count =
|
|||
rp
|
||||
|
||||
updateNPCs
|
||||
:: MonadIO m
|
||||
:: MonadIO m
|
||||
=> M.Matrix (Maybe ImgId)
|
||||
-> [ReachPoint]
|
||||
-> Double
|
||||
|
|
55
src/Test.hs
55
src/Test.hs
|
@ -120,18 +120,19 @@ drawMap :: Affection UserData ()
|
|||
drawMap = do
|
||||
ud <- getAffection
|
||||
dt <- getDelta
|
||||
(_, playerPos) <- yieldSystemT (worldState ud) $ do
|
||||
efor $ \_ -> do
|
||||
(_, (playerPos, npcposs)) <- yieldSystemT (worldState ud) $ do
|
||||
pc <- efor $ \_ -> do
|
||||
with player
|
||||
with pos
|
||||
pos' <- E.get pos
|
||||
pure pos'
|
||||
(_, npcposs) <- yieldSystemT (worldState ud) $ do
|
||||
efor $ \_ -> do
|
||||
-- (_, npcposs) <- yieldSystemT (worldState ud) $ do
|
||||
npcs <- efor $ \_ -> do
|
||||
with npcState
|
||||
with pos
|
||||
pos' <- E.get pos
|
||||
pure pos'
|
||||
return (pc, npcs)
|
||||
let V2 pr pc = head playerPos
|
||||
mat = imgMat (stateData ud)
|
||||
ctx = nano ud
|
||||
|
@ -224,27 +225,29 @@ drawTile
|
|||
-> Maybe ImgId
|
||||
-> IO ()
|
||||
drawTile ai ctx pr pc row col img =
|
||||
do
|
||||
save ctx
|
||||
if (isNothing img)
|
||||
then drawPlayer
|
||||
else do
|
||||
if (Prelude.null mb)
|
||||
then do
|
||||
drawImage
|
||||
drawPlayer
|
||||
else do
|
||||
if (all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
|
||||
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) mincs) ||
|
||||
(all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
|
||||
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) maxcs)
|
||||
then do
|
||||
drawImage
|
||||
drawPlayer
|
||||
when ((realToFrac x > -tileWidth && realToFrac y > -tileHeight) &&
|
||||
(realToFrac x < 1280 && realToFrac (y - (74 - realToFrac tileHeight)) < 720)) $
|
||||
do
|
||||
save ctx
|
||||
if (isNothing img)
|
||||
then drawPlayer
|
||||
else do
|
||||
drawPlayer
|
||||
drawImage
|
||||
restore ctx
|
||||
if (Prelude.null mb)
|
||||
then do
|
||||
drawImage
|
||||
drawPlayer
|
||||
else do
|
||||
if (all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
|
||||
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) mincs) ||
|
||||
(all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
|
||||
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) maxcs)
|
||||
then do
|
||||
drawImage
|
||||
drawPlayer
|
||||
else do
|
||||
drawPlayer
|
||||
drawImage
|
||||
restore ctx
|
||||
where
|
||||
tileWidth = 64 :: Double
|
||||
tileHeight = 32 :: Double
|
||||
|
@ -253,9 +256,9 @@ drawTile ai ctx pr pc row col img =
|
|||
mincs = Prelude.map (snd . matmin) mb
|
||||
maxcs = Prelude.map (snd . matmax) mb
|
||||
x = realToFrac $ 640 + ((fromIntegral col - pc) +
|
||||
(fromIntegral row - pr)) * (tileWidth / 2)
|
||||
(fromIntegral row - pr)) * (tileWidth / 2) :: CFloat
|
||||
y = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) -
|
||||
(fromIntegral col - pc)) * (tileHeight / 2)
|
||||
(fromIntegral col - pc)) * (tileHeight / 2) :: CFloat
|
||||
dist = distance (V2 (fromIntegral row) (fromIntegral col))
|
||||
(V2 (realToFrac pr - 1) (realToFrac pc)) / 4
|
||||
fact =
|
||||
|
|
Loading…
Reference in a new issue