Add trajectory to grenades, various refactoring

This commit is contained in:
2021-09-25 18:39:53 +01:00
parent a0340eb024
commit 32367b5b2d
32 changed files with 339 additions and 253 deletions
+6 -6
View File
@@ -24,10 +24,10 @@ import System.Random
updateBlocks :: World -> World
updateBlocks w
= (\w' -> seq (_wallsZone w') w')
$ flip (foldr removeFromZone) deadPanes
$ flip (foldl' $ flip removeFromZone) deadPanes
$ over walls (\wls -> wls `seq` IM.filter (not . blockIsDead) wls) degradeBlocks
where
degradeBlocks = deadBlocks `seq` foldr killBlock w deadBlocks
degradeBlocks = deadBlocks `seq` foldl' (flip killBlock) w deadBlocks
removeFromZone :: Wall -> World -> World
removeFromZone bl = over (wallsZone . znObjects . ix x . ix y) (IM.delete (_wlID bl))
where
@@ -40,7 +40,7 @@ updateBlocks w
{- | Destroy a block.
Plays destruction sound and sets to be displayed other walls that were shadowed by this wall. -}
killBlock :: Wall -> World -> World
killBlock bl w = f bl . flip (foldr unshadow) (_blShadows bl) $ w
killBlock bl w = f bl . flip (foldl' $ flip unshadow) (_blShadows bl) $ w
where
f :: Wall -> World -> World
f bl'
@@ -84,7 +84,7 @@ pushPointTowardsBy
pushPointTowardsBy x p ps = do
xs <- replicateM (length ps) $ state $ randomR (0, x / fromIntegral (length ps))
let toAdd p' y = y *.* (p' -.- p)
return $ p +.+ foldr1 (+.+) (zipWith toAdd ps xs)
return $ p +.+ foldl1' (+.+) (zipWith toAdd ps xs)
shrinkPolygon
:: RandomGen g
@@ -105,7 +105,7 @@ addBlock (p:ps) hp col isSeeThrough degradability w
| hp <= 0 && null degradability = w
| hp <= 0 = addBlock (p:ps) (head degradability + hp) col isSeeThrough (tail degradability) w
| otherwise = w
& wallsZone . znObjects %~ flip (IM.foldr wallInZone) panes
& wallsZone . znObjects %~ flip (IM.foldl' $ flip wallInZone) panes
& walls %~ IM.union panes
where
lns = zip (p:ps) (ps ++ [p])
@@ -128,7 +128,7 @@ addBlock (p:ps) hp col isSeeThrough degradability w
wallInZone wl
| uncurry dist (_wlLine wl) <= 2*zoneSize
= insertIMInZone x y wlid wl
| otherwise = flip (foldr (\(a,b) -> insertIMInZone a b wlid wl)) ips
| otherwise = flip (foldl' $ flip (\(a,b) -> insertIMInZone a b wlid wl)) ips
where
(x,y) = zoneOfPoint $ uncurry pHalf (_wlLine wl)
wlid = _wlID wl