Tweak creature cliff interaction, using updateCarriage

This commit is contained in:
2026-04-05 15:14:50 +01:00
parent 22a1162e14
commit d5c98f7c4e
4 changed files with 130 additions and 100 deletions
+9 -62
View File
@@ -1,18 +1,15 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Creature.Update (updateCreature) where
import Dodge.WorldEvent.ThingsHit
import Dodge.Base.You
import Control.Monad
import Color
import qualified Data.IntMap.Strict as IM
import qualified Data.List as List
import Data.Maybe
import Dodge.Barreloid
-- import Dodge.Base.NewID
import Dodge.Corpse.Make
import Dodge.Creature.Action
import Dodge.Creature.Radius
import Dodge.Creature.State
import Dodge.Creature.State.WalkCycle
import Dodge.Creature.Vocalization
@@ -25,14 +22,12 @@ import Dodge.Inventory
import Dodge.Lampoid
import Dodge.Prop.Gib
import Dodge.SoundLogic
import Dodge.Update.Camera.Rotate
import FoldableHelp
import Geometry
import LensHelp
import Linear
import NewInt
import RandomHelp
import SDL (MouseButton (..))
import Shape
import ShapePicture.Data
@@ -41,7 +36,7 @@ import ShapePicture.Data
updateCreature :: Creature -> World -> World
updateCreature cr
| cr ^. crPos . _z < negate 300 = (tocr . crHP .~ CrDestroyed Pitted) . destroyAllInvItems cr
| CrIsCorpse _ <- cr ^. crHP = updateCarriage (_crID cr) . chasmTestCorpse cr
| CrIsCorpse _ <- cr ^. crHP = updateCarriage (_crID cr)
| null (cr ^? crHP . _HP) = id
| otherwise = updateLivingCreature cr
where
@@ -49,7 +44,7 @@ updateCreature cr
updateLivingCreature :: Creature -> World -> World
updateLivingCreature cr =
chasmTestLiving cr . case _crType cr of
case _crType cr of
Avatar{} ->
(cWorld . lWorld . creatures . ix 0 . crType . avatarPulse %~ updatePulse)
. crUpdate cid
@@ -130,7 +125,8 @@ startDeathTimer cr = cr
toDeathCarriage :: Carriage -> Carriage
toDeathCarriage = \case
Flying {} -> Falling
x -> x
Walking -> OnGround
_ -> Falling
-- could look at the amount of damage here (given by maxDamage) too
corpseOrGib :: Creature -> World -> World
@@ -142,7 +138,7 @@ corpseOrGib cr = case cr ^? crDamage . to maxDamageType . _Just . _1 of
sethp (CrIsCorpse $ poisonSPic thecorpse)
. dodeathsound PoisonDeath
Just PhysicalDamage
| _crPain cr > 200 ->
| _crPain cr > 300 ->
makeCrGibs cr
. sethp (CrDestroyed Gibbed)
. dodeathsound GibsDeath
@@ -172,59 +168,10 @@ poisonSPic = _1 %~ overColSH (mixColors 0.5 0.5 green . normalizeColor)
dropAll :: Creature -> World -> World
dropAll cr w = foldl' (flip (dropItem cr)) w . reverse . IM.keys . _unNIntMap $ _crInv cr
chasmTestLiving :: Creature -> World -> World
chasmTestLiving cr w
| Flying {} <- cr ^. crStance . carriage = w
| Falling {} <- cr ^. crStance . carriage = w
| Just (x, y) <- List.find g (w ^. cWorld . cliffs) =
w
& soundContinue (CrChasm (_crID cr)) (cr ^. crPos . _xy) debrisS (Just 100)
& tocr . crPos . _xy -~ normalizeV (vNormal (x - y))
& chasmRotate cr (x - y)
| any f (w ^. cWorld . chasms) = w & tocr %~ startFalling
| otherwise = w
where
tocr = cWorld . lWorld . creatures . ix (_crID cr)
g = uncurry $ crOnSeg cr
f = pointInPoly (cr ^. crPos . _xy)
startFalling :: Creature -> Creature
startFalling cr = case cr ^. crStance . carriage of
Walking -> cr & crStance . carriage .~ Falling
_ -> cr & crStance . carriage .~ Falling
chasmTestCorpse :: Creature -> World -> World
chasmTestCorpse cr w
| (xy:xys) <- filter g (w ^. cWorld . cliffs) =
w
& soundContinue (CrChasm (_crID cr)) (cr ^. crPos . _xy) debrisS (Just 100)
& tocr . crPos . _xy +~ h xy xys
| any f (w ^. cWorld . chasms) = w & tocr %~ startFalling
| otherwise = w
where
h :: (Point2,Point2) -> [(Point2,Point2)] -> Point2
h (x,y) [] = normalizeV (vNormal (x-y))
h x (y:_) = unitVectorAtAngle $ tweenAngles (d1/(d1+d2)) (h' x) (h' y)
where
h' :: (Point2,Point2) -> Float
h' = argV . vNormal . uncurry (-)
d a = uncurry closestPointOnLine a (cr ^. crPos . _xy)
d1 :: Float
d1 = norm (cxy - d x)
d2 :: Float
d2 = norm (cxy - d y)
cxy = cr ^. crPos . _xy
tocr = cWorld . lWorld . creatures . ix (_crID cr)
g = uncurry $ circOnSeg cxy (crRad $ cr ^. crType)
f = pointInPoly cxy
chasmRotate :: Creature -> Point2 -> World -> World
chasmRotate cr v w
| t = rotateTo8 (argV v) w
| otherwise = w
where
t = cr ^. crID == 0 && null (w ^? input . mouseButtons . ix SDL.ButtonRight)
--startFalling :: Creature -> Creature
--startFalling cr = case cr ^. crStance . carriage of
-- Walking -> cr & crStance . carriage .~ Falling
-- _ -> cr & crStance . carriage .~ Falling
updatePulse :: Pulse -> Pulse
updatePulse p