Corpses fall down cliff edges

This commit is contained in:
2026-02-10 23:19:44 +00:00
parent 1d85ee6330
commit ed86d310d5
2 changed files with 104 additions and 68 deletions
+73 -37
View File
@@ -1,22 +1,17 @@
module Dodge.Creature.Update (updateCreature) where
import Dodge.Update.Camera.Rotate
import SDL (MouseButton (..))
import Dodge.Creature.Vocalization
import RandomHelp
import Data.Maybe
import Linear
import NewInt
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.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
import Dodge.Creature.YourControl
import Dodge.Damage
import Dodge.Data.Damage.Type
@@ -26,9 +21,14 @@ 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
@@ -36,25 +36,28 @@ import ShapePicture.Data
-- allow for knockbacks etc to be determined as well as intended movements
updateCreature :: Creature -> World -> World
updateCreature cr
| null (cr ^? crHP . _HP) = id
| cr ^. crPos . _z < negate 100 = (tocr . crHP .~ CrIsPitted) . destroyAllInvItems cr
| CrIsCorpse _ <- cr ^. crHP = chasmTestCorpse cr
| null (cr ^? crHP . _HP) = id
| cr ^. crPos . _z < 0 = (tocr . crZVel -~ 0.5) . (tocr . crPos . _z +~ _crZVel cr)
| otherwise = updateCreature' cr
| otherwise = updateLivingCreature cr
where
tocr = cWorld . lWorld . creatures . ix (_crID cr)
updateCreature' :: Creature -> World -> World
updateCreature' cr =
chasmTest cr . case _crType cr of
updateLivingCreature :: Creature -> World -> World
updateLivingCreature cr =
chasmTestLiving cr . case _crType cr of
Avatar{} ->
(cWorld . lWorld . creatures . ix 0 . crType . avatarPulse %~ updatePulse)
. crUpdate cid . yourControl cr
. crUpdate cid
. yourControl cr
LampCrit{} -> updateLampoid cr
BarrelCrit bt -> updateBarreloid bt cr
AvatarDead -> id
ChaseCrit {} -> \w -> crUpdate cid . performActions cid
$ over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
_ -> crUpdate cid
ChaseCrit{} -> \w ->
crUpdate cid . performActions cid $
over (cWorld . lWorld . creatures . ix cid) (chaseCritInternal w) w
_ -> crUpdate cid
where
cid = cr ^. crID
@@ -78,36 +81,47 @@ checkDeath cid w = maybe id checkDeath' (w ^? cWorld . lWorld . creatures . ix c
checkDeath' :: Creature -> World -> World
checkDeath' cr w = case cr ^. crHP of
HP x | x > 0 -> w & tocr . crDamage .~ []
HP x | x > -200 && _crDeathTimer cr < 5 -> w
& tocr . crDamage .~ []
& tocr . crDeathTimer +~ 1
HP _ -> w
HP x
| x > -200 && _crDeathTimer cr < 5 ->
w
& tocr . crDamage .~ []
& tocr . crDeathTimer +~ 1
HP _ ->
w
& dropAll cr -- the order of these is possibly important
& stopSoundFrom (CrWeaponSound (_crID cr) 0)
& corpseOrGib cr
_ -> w
_ -> w
where
tocr = cWorld . lWorld . creatures . ix (_crID cr)
-- could look at the amount of damage here (given by maxDamage) too
corpseOrGib :: Creature -> World -> World
corpseOrGib cr = case cr ^? crDamage . to maxDamageType . _Just . _1 of
Just CookingDamage -> sethp (CrIsCorpse $ scorchSPic thecorpse)
. dodeathsound CookDeath
Just PoisonDamage -> sethp (CrIsCorpse $ poisonSPic thecorpse)
Just CookingDamage ->
sethp (CrIsCorpse $ scorchSPic thecorpse)
. dodeathsound CookDeath
Just PoisonDamage ->
sethp (CrIsCorpse $ poisonSPic thecorpse)
. dodeathsound PoisonDeath
Just PhysicalDamage | _crPain cr > 200
-> addCrGibs cr . sethp CrIsGibs
. dodeathsound GibsDeath
_ -> sethp (CrIsCorpse thecorpse)
Just PhysicalDamage
| _crPain cr > 200 ->
addCrGibs cr
. sethp CrIsGibs
. dodeathsound GibsDeath
_ ->
sethp (CrIsCorpse thecorpse)
. dodeathsound PlainDeath
where
dodeathsound dt = f dt . stopSoundFrom (CrMouth cid)
f dt w = fromMaybe w $ do
let (msid, g) = runState (maybeTakeOne (crDeathSounds cr dt)) (_randGen w)
sid <- msid
return $ w & soundStart (CrMouth cid) (cr ^. crPos . _xy) sid Nothing
& randGen .~ g
return $
w
& soundStart (CrMouth cid) (cr ^. crPos . _xy) sid Nothing
& randGen
.~ g
cid = cr ^. crID
sethp x = cWorld . lWorld . creatures . ix (_crID cr) . crHP .~ x
thecorpse = makeCorpse cr
@@ -122,12 +136,15 @@ 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
chasmTest :: Creature -> World -> World
chasmTest cr w
| _crZVel cr < 0 = w & tocr . crZVel -~ 0.5
chasmTestLiving :: Creature -> World -> World
chasmTestLiving cr w
| _crZVel cr < 0 =
w
& tocr . crZVel -~ 0.5
& tocr . crPos . _z +~ _crZVel cr
-- | Just (x, y) <- List.find g (foldMap loopPairs $ w ^. cWorld . chasms') = w
| Just (x, y) <- List.find g (w ^. cWorld . cliffs) = w
-- | Just (x, y) <- List.find g (foldMap loopPairs $ w ^. cWorld . chasms') = 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)
@@ -138,8 +155,27 @@ chasmTest cr w
g = uncurry $ circOnSeg (cr ^. crPos . _xy) (crRad $ cr ^. crType)
f = circInPolygon (cr ^. crPos . _xy) (crRad $ cr ^. crType)
chasmTestCorpse :: Creature -> World -> World
chasmTestCorpse cr w
| _crZVel cr < 0 =
w
& tocr . crZVel -~ 0.5
& tocr . crPos . _z +~ _crZVel cr
-- | Just (x, y) <- List.find g (foldMap loopPairs $ w ^. cWorld . chasms') = 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 . crZVel -~ 0.5
| otherwise = w
where
tocr = cWorld . lWorld . creatures . ix (_crID cr)
g = uncurry $ circOnSeg (cr ^. crPos . _xy) (crRad $ cr ^. crType)
f = circInPolygon (cr ^. crPos . _xy) (crRad $ cr ^. crType)
chasmRotate :: Creature -> Point2 -> World -> World
chasmRotate cr v w
chasmRotate cr v w
| t = rotateTo8 (argV v) w
| otherwise = w
where