Unshadow window blocks when neighbour destroyed

This commit is contained in:
2021-10-27 11:44:09 +01:00
parent 15fac3db6e
commit 8f738410c0
5 changed files with 33 additions and 13 deletions
+25 -6
View File
@@ -16,6 +16,7 @@ import Dodge.Update.Camera
import Dodge.SoundLogic
import Dodge.Inventory
import Geometry
import Geometry.ConvexPoly
import Geometry.Vector3D
import SDL (MouseButton (..))
@@ -80,22 +81,40 @@ functionalUpdate w = case _menuLayers w of
where
(x,y) = cloudZoneOfPoint $ stripZ $ _clPos cl
splinterBlock :: Block' -> World -> World
splinterBlock bl w = foldr unshadowBlock w (_blShadows' bl) -- foldr shiftTowardCen w (_blWallIDs bl)
& blocks . ix (_blID bl) . blHPs %~ tail
where
wls = map (_walls w IM.!) (_blWallIDs bl)
ps = map (fst . _wlLine) wls
cen = centroid ps
shiftTowardCen wlid = walls . ix wlid . wlLine %~ bimap f f
f x = 0.5 *.* (x +.+ cen)
unshadowBlock :: Int -> World -> World
unshadowBlock wlid w = case w ^? walls . ix wlid of
Just wl -> w
& walls . ix wlid . blVisible .~ True
& wallsZone . znObjects . ix x . ix y . ix wlid . blVisible .~ True
where
(x,y) = zoneOfPoint $ uncurry pHalf (_wlLine wl)
Nothing -> w
updateBlocks :: World -> World
updateBlocks w = foldr f w $ _blocks w
where
f bl w'
| head (_blHPs bl) < 1 = w'
f bl w' = case safeHead $ _blHPs bl of
Just x | x < 1 -> splinterBlock bl w'
| otherwise -> w'
Nothing -> w'
& walls %~ removeIDs (_blWallIDs bl)
& flip (foldr removeFromZone) (_blWallIDs bl)
& blocks %~ IM.delete (_blID bl)
| otherwise = w'
removeIDs is wls = foldr IM.delete wls is
removeFromZone wlid w' = over (wallsZone . znObjects . ix x . ix y) (IM.delete (_wlID wl)) w'
--removeFromZone wlid w' = set (wallsZone . znObjects) IM.empty w'
--removeFromZone wlid w' = over (wallsZone . znObjects . ix x . ix y . ix (_wlID wl)) setCol w'
where
(x,y) = zoneOfPoint $ uncurry pHalf (_wlLine wl)
wl = _walls w IM.! wlid
wl = _walls w IM.! wlid -- note the use of w not w'
setCol = wlColor .~ V4 1 1 0 1
-- | Note the explict use of record syntax. Using lens creates a space leak.