Slime crit collisions

This commit is contained in:
2026-04-12 19:11:01 +01:00
parent f0da9b5f8c
commit 8a57aa2f2c
5 changed files with 21 additions and 3 deletions
+16 -1
View File
@@ -1002,7 +1002,13 @@ crCrSpring c1 c2
| diffheight = id
| SlimeCrit{} <- c1 ^. crType
, SlimeCrit{} <- c2 ^. crType
, id2 > id1 = fuseSlimes c1 c2
, id2 > id1
, distance xy1 xy2 < abs (r1 - r2) + 1 = fuseSlimes c1 c2
| SlimeCrit{} <- c1 ^. crType =
--cWorld . lWorld . creatures %~ (rolap c1 c2 . rolap' c2 c1)
cWorld . lWorld . creatures %~ (rolap . rolap')
| SlimeCrit{} <- c2 ^. crType = id
-- cWorld . lWorld . creatures %~ ( rolap c1 c2 . rolap' c2 c1)
| otherwise = cWorld . lWorld . creatures %~ ( olap c1 c2 . olap' c2 c1)
where
z c = c ^. crPos . _z
@@ -1013,13 +1019,22 @@ crCrSpring c1 c2
return $ z c1 > h2 || z c2 > h1
olap a b = ix (a ^. crID) . crPos . _xy +~ overlap b
olap' a b = ix (a ^. crID) . crPos . _xy -~ overlap b
suckx = min 1 (2 * (1 - distance xy1 xy2 / (r1 + r2)))
rolap = ix id1 . crPos . _xy +~ (2*m2 / (m1+m2)) *^ normalize (xy2 - xy1)
rolap' = ix id2 . crPos . _xy +~ (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
id1 = _crID c1
id2 = _crID c2
xy1 = c1 ^. crPos . _xy
xy2 = c2 ^. crPos . _xy
vec = c1 ^. crPos . _xy - c2 ^. crPos . _xy
diff = magV vec
r1 = crRad (c1 ^. crType)
r2 = crRad (c2 ^. crType)
comRad = crRad (c1 ^. crType) + crRad (c2 ^. crType)
overlap c = ((comRad - diff) * crMass (_crType c) * 0.5 / massT) *^ signorm vec
massT = crMass (_crType c1) + crMass (_crType c2)
m1 = crMass $ c1 ^. crType
m2 = crMass $ c2 ^. crType
fuseSlimes :: Creature -> Creature -> World -> World
fuseSlimes c1 c2 = (cWorld . lWorld . creatures . ix i1 .~ c)