Cleanup
This commit is contained in:
+23
-26
@@ -1,3 +1,5 @@
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Dodge.Barreloid (updateBarreloid) where
|
||||
|
||||
import Data.List
|
||||
@@ -9,37 +11,32 @@ import Dodge.Spark
|
||||
import Dodge.WorldEvent.Explosion
|
||||
import Geometry
|
||||
import LensHelp
|
||||
import System.Random
|
||||
|
||||
updateBarreloid :: Creature -> World -> World
|
||||
updateBarreloid cr = case cr ^?! crType . barrelType of
|
||||
ExplosiveBarrel{} -> updateExpBarrel cr
|
||||
PlainBarrel -> updateBarrel cr
|
||||
updateBarreloid :: BarrelType -> Creature -> World -> World
|
||||
updateBarreloid = \case
|
||||
ExplosiveBarrel ps -> updateExpBarrel ps
|
||||
PlainBarrel -> updateBarrel
|
||||
|
||||
-- should generate the sparks externally using new random generators
|
||||
updateExpBarrel :: Creature -> World -> World
|
||||
updateExpBarrel cr w
|
||||
| _crHP cr > 0 = foldl' (flip ($)) (hiss w & cWorld . lWorld . creatures . at (_crID cr) .~ newCr) pierceSparks
|
||||
| otherwise = makeExplosionAt (_crPos cr) 0 $ stopSounds w & cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
|
||||
updateExpBarrel :: [Point2] -> Creature -> World -> World
|
||||
updateExpBarrel ps cr w
|
||||
| cr ^. crHP > 0 =
|
||||
w
|
||||
& hiss
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) %~ damsToExpBarrel damages
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crHP
|
||||
-~ length (_piercedPoints . _barrelType $ _crType cr)
|
||||
& cWorld . lWorld . creatures . ix (_crID cr) . crDamage .~ mempty
|
||||
& flip (foldl' f) ps
|
||||
| otherwise =
|
||||
w
|
||||
& makeExplosionAt (cr ^. crPos) 0
|
||||
& cWorld . lWorld . creatures . at (_crID cr) .~ Nothing
|
||||
where
|
||||
g = _randGen w
|
||||
f w' p = makeSpark NormalSpark (p + normalizeV p + cr ^. crPos) (argV p) w'
|
||||
damages = cr ^. crDamage
|
||||
pierceSparks :: [World -> World]
|
||||
pierceSparks =
|
||||
zipWith
|
||||
(\p a -> sparkRandDir 0.1 (_crPos cr +.+ p) (a + argV p))
|
||||
poss
|
||||
as
|
||||
as = randomRs (-0.7, 0.7) g
|
||||
poss = _piercedPoints $ _barrelType $ _crType cr
|
||||
newCr = Just $ applyFuseDamage $ set crDamage [] $ damsToExpBarrel damages cr
|
||||
applyFuseDamage cr' =
|
||||
cr' & crHP
|
||||
%~ subtract (length . _piercedPoints . _barrelType $ _crType cr')
|
||||
hiss
|
||||
| null poss = id
|
||||
| otherwise = soundMultiFrom [BarrelHiss 0, BarrelHiss 1] (_crPos cr) foamSprayLoopS (Just 1)
|
||||
stopSounds = stopSoundFrom (BarrelHiss 0) . stopSoundFrom (BarrelHiss 1)
|
||||
| null ps = id
|
||||
| otherwise = soundContinue (BarrelHiss (_crID cr)) (_crPos cr) foamSprayLoopS (Just 1)
|
||||
|
||||
updateBarrel :: Creature -> World -> World
|
||||
updateBarrel cr
|
||||
|
||||
@@ -15,7 +15,7 @@ updateCreature cr = case _crType cr of
|
||||
Avatar{} -> (cWorld . lWorld . creatures . ix 0 . crType . avatarPulse %~ updatePulse)
|
||||
. crUpdate yourControl cr
|
||||
LampCrit{} -> updateLampoid cr
|
||||
BarrelCrit{} -> updateBarreloid cr
|
||||
BarrelCrit bt -> updateBarreloid bt cr
|
||||
AvatarDead -> id
|
||||
_ -> updateHumanoid cr
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ makeFlameExplosionAt p w =
|
||||
makeExplosionAt :: Point2 -> Point2 -> World -> World
|
||||
makeExplosionAt p vel w =
|
||||
w
|
||||
& soundMultiFrom [Explosion 0, Explosion 1] p bangS Nothing
|
||||
& soundStart (Explosion (w ^. cWorld . lWorld . lClock)) p bangS Nothing
|
||||
& addFlames
|
||||
& cWorld . lWorld . worldEvents
|
||||
.:~ MakeTempLight (LSParam (addZ 20 p) 150 (V3 1 0.5 0)) 20
|
||||
|
||||
Reference in New Issue
Block a user