Refactor slime update
This commit is contained in:
@@ -61,6 +61,7 @@ tutAnoTree = do
|
||||
, tToBTree "" . return . cleatOnward <$> ((putSingleLight =<< roomRectAutoLights 300 300)
|
||||
<&> rmPmnts <>~ [sps0 (PutCrit slimeCrit) & plSpot . psPos .~ V2 150 100
|
||||
, sps0 (PutCrit chaseCrit) & plSpot . psPos .~ V2 250 100
|
||||
, sps0 (PutCrit hoverCrit) & plSpot . psPos .~ V2 250 50
|
||||
]
|
||||
)
|
||||
-- , tToBTree "" . return . cleatOnward <$> (cChasm
|
||||
|
||||
+24
-7
@@ -1009,8 +1009,9 @@ crCrSpring c1 c2
|
||||
, distance xy1 xy2 < r1 - (r2 + 5)
|
||||
= feedSlime c1 c2
|
||||
| Just t <- c1 ^? crType . slimeSplitTimer
|
||||
, t <= 0 =
|
||||
cWorld . lWorld . creatures %~ (rolap . rolap')
|
||||
, slimeFood c2
|
||||
, t <= 0 = slimeSuck c1 c2
|
||||
-- cWorld . lWorld . creatures %~ (rolap . rolap')
|
||||
| SlimeCrit{} <- c1 ^. crType = id
|
||||
| SlimeCrit{} <- c2 ^. crType = id
|
||||
| otherwise = cWorld . lWorld . creatures %~ ( olap c1 c2 . olap' c2 c1)
|
||||
@@ -1024,8 +1025,8 @@ crCrSpring c1 c2
|
||||
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))) ^ (2:: Int)
|
||||
rolap = ix id1 . crPos . _xy +~ f (suckx * 1.5 * m2 / (m1+m2)) *^ normalize (xy2 - xy1)
|
||||
rolap' = ix id2 . crPos . _xy +~ f (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
|
||||
-- rolap = ix id1 . crPos . _xy +~ f (suckx * 1.5 * m2 / (m1+m2)) *^ normalize (xy2 - xy1)
|
||||
-- rolap' = ix id2 . crPos . _xy +~ f (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
|
||||
f = min (distance xy1 xy2/2)
|
||||
id1 = _crID c1
|
||||
id2 = _crID c2
|
||||
@@ -1041,6 +1042,22 @@ crCrSpring c1 c2
|
||||
m1 = crMass $ c1 ^. crType
|
||||
m2 = crMass $ c2 ^. crType
|
||||
|
||||
slimeSuck :: Creature -> Creature -> World -> World
|
||||
slimeSuck c1 c2 = cWorld . lWorld . creatures %~ (rolap . rolap')
|
||||
where
|
||||
suckx = (min 1 $ 2 * (1 - distance xy1 xy2 / (r1 + r2))) ^ (2:: Int)
|
||||
rolap = ix id1 . crPos . _xy +~ f (suckx * 1.5 * m2 / (m1+m2)) *^ normalize (xy2 - xy1)
|
||||
rolap' = ix id2 . crPos . _xy +~ f (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
|
||||
f = min (distance xy1 xy2/2)
|
||||
id1 = _crID c1
|
||||
id2 = _crID c2
|
||||
xy1 = c1 ^. crPos . _xy
|
||||
xy2 = c2 ^. crPos . _xy
|
||||
r1 = crRad (c1 ^. crType)
|
||||
r2 = crRad (c2 ^. crType)
|
||||
m1 = crMass $ c1 ^. crType
|
||||
m2 = crMass $ c2 ^. crType
|
||||
|
||||
slimeFood :: Creature -> Bool
|
||||
slimeFood cr = case cr ^. crType of
|
||||
Avatar{} -> True
|
||||
@@ -1053,7 +1070,7 @@ feedSlime s c w = fromMaybe w $ do
|
||||
ch <- crHeight c
|
||||
return $ if min 10 r1 + s ^?! crType . slimeFeedProgress < max 15 (ch + 2)
|
||||
then w & cWorld . lWorld . creatures . ix (s ^. crID) . crType . slimeFeedProgress %~ (min r1 . (+0.7))
|
||||
& cWorld . lWorld . creatures %~ (rolap . rolap')
|
||||
& slimeSuck s c
|
||||
else
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix (c ^. crID) . crHP .~ CrDestroyed Swallowed
|
||||
@@ -1068,8 +1085,8 @@ feedSlime s c w = fromMaybe w $ do
|
||||
r = sqrt (r1*r1 + 4*r2*r2)
|
||||
id1 = s ^. crID
|
||||
id2 = c ^. crID
|
||||
rolap = ix id1 . crPos . _xy +~ f' (suckx * 1.5 * m2 / (m1+m2)) *^ normalize (xy2 - xy1)
|
||||
rolap' = ix id2 . crPos . _xy +~ f' (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
|
||||
-- rolap = ix id1 . crPos . _xy +~ f' (suckx * 1.5 * m2 / (m1+m2)) *^ normalize (xy2 - xy1)
|
||||
-- rolap' = ix id2 . crPos . _xy +~ f' (suckx * 1.5*m1 / (m1+m2)) *^ normalize (xy1 - xy2)
|
||||
m1 = crMass $ s ^. crType
|
||||
m2 = crMass $ c ^. crType
|
||||
suckx = (min 1 $ 2 * (1 - distance xy1 xy2 / (r1 + r2))) ^ (2:: Int)
|
||||
|
||||
Reference in New Issue
Block a user