From 8a57aa2f2cd1d5148821950c80e74831a13d3e22 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 12 Apr 2026 19:11:01 +0100 Subject: [PATCH] Slime crit collisions --- src/Dodge/Creature/ChaseCrit.hs | 1 + src/Dodge/Creature/Picture.hs | 2 +- src/Dodge/Creature/Test.hs | 3 ++- src/Dodge/Data/ActionPlan.hs | 1 + src/Dodge/Update.hs | 17 ++++++++++++++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Dodge/Creature/ChaseCrit.hs b/src/Dodge/Creature/ChaseCrit.hs index 35de0512c..d219fc2fe 100644 --- a/src/Dodge/Creature/ChaseCrit.hs +++ b/src/Dodge/Creature/ChaseCrit.hs @@ -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 = diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 592237f3e..4e80bcad5 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -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) diff --git a/src/Dodge/Creature/Test.hs b/src/Dodge/Creature/Test.hs index f186a90fc..2e321cde9 100644 --- a/src/Dodge/Creature/Test.hs +++ b/src/Dodge/Creature/Test.hs @@ -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 diff --git a/src/Dodge/Data/ActionPlan.hs b/src/Dodge/Data/ActionPlan.hs index 8c502b93a..1cd8a3ec3 100644 --- a/src/Dodge/Data/ActionPlan.hs +++ b/src/Dodge/Data/ActionPlan.hs @@ -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 diff --git a/src/Dodge/Update.hs b/src/Dodge/Update.hs index 661985ac1..161400aba 100644 --- a/src/Dodge/Update.hs +++ b/src/Dodge/Update.hs @@ -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)