Allow slime to eat creatures

This commit is contained in:
2026-04-15 23:40:04 +01:00
parent 9710bb5c83
commit a8b79a59c7
4 changed files with 271 additions and 230 deletions
+28 -3
View File
@@ -1004,6 +1004,10 @@ crCrSpring c1 c2
, SlimeCrit{} <- c2 ^. crType
, id2 > id1
, distance xy1 xy2 < abs (r1 - r2) + 1 = fuseSlimes c1 c2
| SlimeCrit{} <- c1 ^. crType
, slimeFood c2
, distance xy1 xy2 < r1 - (r2 + 5)
= feedSlime c1 c2
| Just t <- c1 ^? crType . slimeSplitTimer
, t <= 0 =
cWorld . lWorld . creatures %~ (rolap . rolap')
@@ -1037,13 +1041,32 @@ crCrSpring c1 c2
m1 = crMass $ c1 ^. crType
m2 = crMass $ c2 ^. crType
slimeFood :: Creature -> Bool
slimeFood cr = case cr ^. crType of
Avatar{} -> True
ChaseCrit{} -> True
_ -> False
feedSlime :: Creature -> Creature -> World -> World
feedSlime s c w = w
& cWorld . lWorld . creatures . ix (c ^. crID) . crHP .~ CrDestroyed Swallowed
& cWorld . lWorld . creatures . ix (s ^. crID) %~ f
& slimeEatSound (s ^. crID) (s ^. crPos . _xy)
where
f cr = cr & crType . slimeRad .~ r
& crType . slimeRadWobble +~ r - r1
& crType . slimeCompression %~ ((r/r1) *^)
r1 = s ^?! crType . slimeRad
r2 = 2 * c ^. crType . to crRad
r = sqrt (r1*r1 + r2*r2)
fuseSlimes :: Creature -> Creature -> World -> World
fuseSlimes c1 c2 = (cWorld . lWorld . creatures . ix mini .~ c)
. (cWorld . lWorld . creatures . at maxi .~ Nothing)
. dosound
. slimeEatSound i1 (c ^. crPos . _xy)
where
c' | c1 ^?! crType . slimeRad > c2 ^?! crType . slimeRad = c1
| otherwise = c2
| otherwise = c2
mini = min i1 i2
maxi = max i1 i2
i1 = c1 ^. crID
@@ -1055,7 +1078,9 @@ fuseSlimes c1 c2 = (cWorld . lWorld . creatures . ix mini .~ c)
r1 = c1 ^?! crType . slimeRad
r2 = c2 ^?! crType . slimeRad
r = sqrt (r1*r1 + r2*r2)
dosound w = w & soundStart (CrSound i1) (c ^. crPos . _xy) s Nothing
slimeEatSound :: Int -> Point2 -> World -> World
slimeEatSound i p w = w & soundStart (CrSound i) p s Nothing
& randGen .~ g
where
(s,g) = runState (takeOne [slurp1S,slurp2S,slurp3S,slurp4S,slurp5S]) (w ^. randGen)