Make creature update an external function
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
module Dodge.Barreloid where
|
||||
import Dodge.Data
|
||||
import Dodge.WorldEvent.Explosion
|
||||
import Dodge.Spark
|
||||
import Dodge.Creature.State
|
||||
import Geometry
|
||||
import Dodge.SoundLogic
|
||||
import LensHelp
|
||||
|
||||
import System.Random
|
||||
import Data.List
|
||||
|
||||
updateBarreloid :: Creature -> World -> World
|
||||
updateBarreloid cr = case cr ^?! crType . barrelType of
|
||||
ExplosiveBarrel -> updateExpBarrel cr
|
||||
PlainBarrel -> updateBarrel cr
|
||||
|
||||
-- should generate the sparks externally using new random generators
|
||||
updateExpBarrel :: Creature -> World -> World
|
||||
updateExpBarrel cr w
|
||||
| _crHP cr > 0 = foldr ($) (hiss w & creatures . at (_crID cr) .~ newCr) pierceSparks
|
||||
| otherwise = makeExplosionAt (_crPos cr) $ stopSounds w & creatures . at (_crID cr) .~ Nothing
|
||||
where
|
||||
g = _randGen w
|
||||
damages = _csDamage $ _crState cr
|
||||
pierceSparks :: [World -> World]
|
||||
pierceSparks
|
||||
= zipWith3 (\p a -> createBarrelSpark (_crPos cr +.+ p) (a + argV p))
|
||||
poss as colids
|
||||
as = randomRs (-0.7,0.7) g
|
||||
colids = randomRs (0,11) g
|
||||
poss = _piercedPoints $ _csSpState $ _crState cr
|
||||
newCr = Just $ applyFuseDamage $ set (crState . csDamage) [] $ damToExpBarrel damages cr
|
||||
applyFuseDamage cr' = cr' & crHP %~
|
||||
subtract (length . _piercedPoints . _csSpState $ _crState cr')
|
||||
hiss | null poss = id
|
||||
| otherwise = soundMultiFrom [BarrelHiss 0,BarrelHiss 1] (_crPos cr) foamSprayLoopS (Just 1)
|
||||
stopSounds = stopSoundFrom (BarrelHiss 0) . stopSoundFrom (BarrelHiss 1)
|
||||
|
||||
updateBarrel :: Creature -> World -> World
|
||||
updateBarrel cr
|
||||
| _crHP cr > 0 = doDamage cr
|
||||
| otherwise = creatures . at (_crID cr) .~ Nothing
|
||||
|
||||
damToExpBarrel :: [Damage] -> Creature -> Creature
|
||||
damToExpBarrel ds cr = foldr damToExpBarrel' (foldr damToExpBarrel' cr pierceDam) otherDam
|
||||
where
|
||||
(pierceDam,otherDam) = partition isPierce ds
|
||||
isPierce Damage{_dmType = PIERCING{}} = True
|
||||
isPierce _ = False
|
||||
|
||||
damToExpBarrel' :: Damage -> Creature -> Creature
|
||||
damToExpBarrel' dm cr = case _dmType dm of
|
||||
PIERCING -> over (crState . csSpState . piercedPoints) ((:) $ int -.- _crPos cr)
|
||||
$ cr & crHP -~ div amount 200
|
||||
POISONDAM -> cr
|
||||
SPARKING -> cr
|
||||
-- PUSHDAM -> cr LensHelp.& crPos .+.+~ (1 / _crMass cr *.* _dePushBack (_dmEffect dm))
|
||||
_ -> cr LensHelp.& crHP -~ amount
|
||||
where
|
||||
amount = _dmAmount dm
|
||||
int = _dmAt dm
|
||||
Reference in New Issue
Block a user