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
+1
View File
@@ -69,6 +69,7 @@ slimeCrit = defaultCreature
& crType .~ SlimeCrit 40 (V2 30 0) False True
& crFaction .~ ColorFaction (light green)
& crPerception . cpVision . viFOV .~ FloatFOV pi
& crActionPlan .~ SlimeIntelligence
hoverCrit :: Creature
hoverCrit =
+1 -1
View File
@@ -54,7 +54,7 @@ drawCreature w m cr = translateSP (_crPos cr) . fallrot . rotateSP (_crDir cr) $
_ -> id
drawSlimeCrit :: Creature -> Shape
drawSlimeCrit cr = colorSH green $ upperPrismPolyHalf Medium Undesired r $ polyCirc 6 r
drawSlimeCrit cr = colorSH green $ upperPrismPolyHalf Medium Typical r $ polyCirc 6 r
& each %~ scaleAlong d s
& each %~ scaleAlong (vNormal d) (1 / s)
& each %~ rotateV (-cr ^. crDir)
+2 -1
View File
@@ -133,7 +133,8 @@ isAnimate :: Creature -> Bool
{-# INLINE isAnimate #-}
isAnimate cr = case _crActionPlan cr of
Inanimate -> False
_ -> True
SlimeIntelligence -> False
ActionPlan{} -> True
hasAutoDoorBody :: Creature -> Bool
hasAutoDoorBody cr = case cr ^. crHP of
+1
View File
@@ -13,6 +13,7 @@ import Sound.Data
data ActionPlan
= Inanimate
| SlimeIntelligence
| ActionPlan
{ -- _apImpulse :: [Impulse] -- done per frame
_apAction :: Action -- updated per frame, likely persist across frames
+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)