Destruction of slime crits

This commit is contained in:
2026-04-12 09:09:17 +01:00
parent 6f2e862c65
commit d075880248
2 changed files with 22 additions and 20 deletions
+5 -4
View File
@@ -71,6 +71,7 @@ updateLivingCreature cr = case _crType cr of
slimeCritUpdate :: Int -> World -> World
slimeCritUpdate cid w
| r < 5 = w & cWorld . lWorld . creatures . ix cid . crHP .~ CrDestroyed Gibbed
| Just hitp <- w ^? cWorld . lWorld . creatures . ix cid . crDamage . ix 0 . dmPos
, Just hitv <- w ^? cWorld . lWorld . creatures . ix cid . crDamage . ix 0 . dmVector
, Just (cr1,cr2) <- splitSlimeCrit hitp hitv cr
@@ -80,6 +81,7 @@ slimeCritUpdate cid w
& cWorld . lWorld . creatures . at cid' ?~ (cr2 & crID .~ cid')
| otherwise = w
& cWorld . lWorld . creatures . ix cid .~ mvslime
& cWorld . lWorld . creatures . ix cid . crDamage .~ []
where
txy = w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy
cr = w ^?! cWorld . lWorld . creatures . ix cid
@@ -112,17 +114,16 @@ splitSlimeCrit :: Point2 -> Point2 -> Creature -> Maybe (Creature, Creature)
splitSlimeCrit p v cr = do
let mp = closestPointOnLine p (p+v) cxy
h = r - distance mp cxy
nv = normalize v
guard $ h > 0
let a1 = segmentArea r h
a2 = pi*r*r - a1
r1 = sqrt (a1/pi)
r2 = sqrt (a2/pi)
guard $ r1 > 5 && r2 > 5
return (cr' & crPos . _xy +~ r2 *^ vNormal nv
-- guard $ r1 > 5 && r2 > 5
return (cr' & crPos . _xy .~ mp + r1 *^ normalize (mp - cxy)
& crType . slimeRad .~ r1
& crType . slimeCompression .~ V2 r1 0
,cr' & crPos . _xy -~ r1 *^ vNormal nv
,cr' & crPos . _xy .~ mp - r2 *^ normalize (mp - cxy)
& crType . slimeRad .~ r2
& crType . slimeCompression .~ V2 r2 0
)