Work on slime crits

This commit is contained in:
2026-04-13 19:54:11 +01:00
parent 8a57aa2f2c
commit b8bec2c830
14 changed files with 294 additions and 260 deletions
+16 -6
View File
@@ -79,12 +79,13 @@ slimeCritUpdate cid w
let cid' = IM.newKey $ w ^. cWorld . lWorld . creatures
in w & cWorld . lWorld . creatures . ix cid .~ cr1
& cWorld . lWorld . creatures . at cid' ?~ (cr2 & crID .~ cid')
| otherwise = w
| otherwise = updateCarriage cid $ w
& cWorld . lWorld . creatures . ix cid .~ mvslime
& cWorld . lWorld . creatures . ix cid . crDamage .~ []
& cWorld . lWorld . creatures . ix cid . crDir .~ d
& cWorld . lWorld . creatures . ix cid . crType . slimeResetDir .~ rb'
& randGen .~ g
& cWorld . lWorld . creatures . ix cid %~ doSlimeRadChange
where
txy = w ^?! cWorld . lWorld . creatures . ix 0 . crPos . _xy
cr = w ^?! cWorld . lWorld . creatures . ix cid
@@ -110,7 +111,8 @@ slimeCritUpdate cid w
f | abs (norm v - norm p') < 0.2 = not
| otherwise = id
v = (s * r) *^ unitVectorAtAngle (cr ^. crDir)
r = crRad (cr ^. crType)
--r = crRad (cr ^. crType)
r = (cr ^?! crType . slimeRad)
p = cr ^?! crType . slimeCompression
(p',f')
| dot p v > 0 && dot p v > dot p (vNormal v) && dot p v > dot p (-vNormal v) = (p, id)
@@ -119,6 +121,13 @@ slimeCritUpdate cid w
| otherwise = (-(r*r/norm p) *^ normalize (vNormal p), not)
x = 0.1 *^ normalize (v - p')
doSlimeRadChange :: Creature -> Creature
doSlimeRadChange = crType . slimeRadWobble %~ f
where
f x | x > 1 = x - 1
| x < -1 = x + 1
| otherwise = 0
splitSlimeCrit :: Point2 -> Point2 -> Creature -> Maybe (Creature, Creature)
splitSlimeCrit p v cr = do
let mp = closestPointOnLine p (p+v) cxy
@@ -129,14 +138,14 @@ splitSlimeCrit p v cr = do
r1 = sqrt (a1/pi)
r2 = sqrt (a2/pi)
-- guard $ r1 > 5 && r2 > 5
return (cr' & crPos . _xy .~ mp + r1 *^ normalize (mp - cxy)
return (cr' & crPos . _xy .~ mp + (r1 + 0.5) *^ normalize (mp - cxy)
& crType . slimeRad .~ r1
& crType . slimeCompression .~ V2 r1 0
& crType . slimeCompression .~ rotateV (argV (mp-cxy)) (V2 r1 0)
& crDir .~ argV (mp - cxy)
& crType . slimeResetDir .~ not (cr ^?! crType . slimeIsCompressing)
,cr' & crPos . _xy .~ mp - r2 *^ normalize (mp - cxy)
,cr' & crPos . _xy .~ mp - (r2 + 0.5) *^ normalize (mp - cxy)
& crType . slimeRad .~ r2
& crType . slimeCompression .~ V2 r2 0
& crType . slimeCompression .~ rotateV (argV (cxy-mp)) (V2 r2 0)
& crDir .~ argV (cxy - mp)
& crType . slimeResetDir .~ not (cr ^?! crType . slimeIsCompressing)
)
@@ -144,6 +153,7 @@ splitSlimeCrit p v cr = do
cxy = cr ^. crPos . _xy
r = cr ^?! crType . slimeRad
cr' = cr & crDamage .~ []
& crType . slimeRadWobble .~ 0
-- h is the height of the segment, ie r - distance to center
segmentArea :: Float -> Float -> Float