Fix poison gas

This commit is contained in:
2021-08-28 19:24:15 +01:00
parent ef73964d09
commit f977742f06
6 changed files with 42 additions and 16 deletions
+27 -6
View File
@@ -166,17 +166,22 @@ checkEndGame w
| _crHP (you w) < 1 = haltSound $ w {_menuLayers = [GameOverMenu]}
| otherwise = w
--updateClouds :: World -> World
--updateClouds w = w' & clouds %~ mapMaybe (updateCloud w)
updateClouds :: World -> World
updateClouds w = w & clouds %~ mapMaybe (updateCloud w)
--updateClouds w = IM.foldl' updateCloud w $ _clouds w
updateClouds w = w' & clouds .~ catMaybes mclouds
where
(w',mclouds) = mapAccumR updateCloud' w (_clouds w)
-- did i write a mapMaybeAccumR ?
updateCloud :: World -> Cloud -> Maybe Cloud
updateCloud w c
| _clTimer c < 1 = Nothing
| otherwise = Just $ c
updateCloud' :: World -> Cloud -> (World,Maybe Cloud)
updateCloud' w c
| _clTimer c < 1 = (w, Nothing)
| otherwise = (_clEffect c c w, Just $ c
& clPos .~ finalPos
& clVel .~ finalVel
& clTimer -~ 1
)
where
newVel = 0.95 *.* springVels
springVels = foldl' (clClSpringVel c) (_clVel c) (cloudsNearPoint oldPos w)
@@ -186,6 +191,22 @@ updateCloud w c
finalPos = maybe newPos fst hitWl
finalVel = maybe newVel snd hitWl
--updateCloud :: World -> Cloud -> Maybe Cloud
--updateCloud w c
-- | _clTimer c < 1 = Nothing
-- | otherwise = Just $ c
-- & clPos .~ finalPos
-- & clVel .~ finalVel
-- & clTimer -~ 1
-- where
-- newVel = 0.95 *.* springVels
-- springVels = foldl' (clClSpringVel c) (_clVel c) (cloudsNearPoint oldPos w)
-- oldPos = _clPos c
-- newPos = oldPos +.+ newVel
-- hitWl = collideCircWalls' oldPos newPos 5 $ wallsNearPoint newPos w
-- finalPos = maybe newPos fst hitWl
-- finalVel = maybe newVel snd hitWl
clClSpringVel :: Cloud -> Point2 -> Cloud -> Point2
clClSpringVel a v b
| dist pa pb < radDist = v +.+ 0.1 *.* safeNormalizeV (pa -.- pb)