Improve static bullets
This commit is contained in:
@@ -8,6 +8,7 @@ module Dodge.WorldEvent.Explosion
|
||||
, makeTeslaExplosionAt
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.EnergyBall
|
||||
import Dodge.LightSource
|
||||
import Dodge.Flame
|
||||
import Dodge.Base.Collide
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
{- | Creation of particles in the world. -}
|
||||
module Dodge.WorldEvent.SpawnParticle
|
||||
( makeGasCloud
|
||||
, makeFlamelet
|
||||
, aStaticBall
|
||||
, incBall
|
||||
, makeStaticBall
|
||||
, concBall
|
||||
, randParticleAt
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Zone
|
||||
@@ -21,6 +20,17 @@ import LensHelp
|
||||
import Data.Foldable
|
||||
import qualified Streaming.Prelude as S
|
||||
|
||||
randParticleAt :: (Point2 -> State StdGen Particle) -> Point2 -> World -> World
|
||||
randParticleAt f p w = w
|
||||
& instantParticles .:~ thepart
|
||||
& randGen .~ g
|
||||
where
|
||||
(thepart,g) = runState (f p) (_randGen w)
|
||||
|
||||
makeStaticBall :: Point2 -> World -> World
|
||||
makeStaticBall p = randParticleAt aStaticBall p . (posEvents .:~ thesparker)
|
||||
where
|
||||
thesparker = PosEvent SparkSpawner 10 p
|
||||
|
||||
concBall :: Point2 -> State g Particle
|
||||
concBall p = return Shockwave
|
||||
@@ -34,10 +44,9 @@ concBall p = return Shockwave
|
||||
, _ptTimer = 10
|
||||
}
|
||||
|
||||
|
||||
aStaticBall :: Point2 -> State g Particle
|
||||
aStaticBall p = return PtStaticBall
|
||||
{ _ptUpdate = moveStaticBall
|
||||
{ _ptUpdate = moveFlamelet
|
||||
, _ptVel = 0
|
||||
, _ptColor = blue
|
||||
, _ptPos = p
|
||||
@@ -47,48 +56,6 @@ aStaticBall p = return PtStaticBall
|
||||
, _ptZ = 20
|
||||
}
|
||||
|
||||
makeFlamelet
|
||||
:: Point2 -- ^ Position
|
||||
-> Float -- ^ z position
|
||||
-> Point2 -- ^ Velocity
|
||||
-> Float -- ^ Size
|
||||
-> Int -- ^ Timer
|
||||
-> World
|
||||
-> World
|
||||
makeFlamelet (V2 x y) z vel size time w = w
|
||||
& randGen .~ g
|
||||
& instantParticles .:~ PtIncBall
|
||||
{ _ptUpdate = moveFlamelet
|
||||
, _ptVel = vel
|
||||
, _ptColor = red
|
||||
, _ptPos = V2 x y
|
||||
, _ptWidth = size
|
||||
, _ptTimer = time
|
||||
, _ptHitEff = expireAndDamage $ simpleDam FLAMING 1
|
||||
, _ptZ = z
|
||||
, _ptRot = rot
|
||||
}
|
||||
where
|
||||
(rot ,g) = randomR (0,3) $ _randGen w
|
||||
|
||||
--damageBothTypeAmount :: DamageType
|
||||
-- -> Int
|
||||
-- -> Particle
|
||||
-- -> [(Point2, Either Creature Wall)]
|
||||
-- -> World
|
||||
-- -> (World, Maybe Particle)
|
||||
--damageBothTypeAmount dt amount = destroyOnImpact
|
||||
-- (\pt p cr -> creatures . ix (_crID cr) . crState . crDamage .:~ thedam pt p)
|
||||
-- (\pt p -> damageWall (thedam pt p))
|
||||
-- where
|
||||
-- thedam pt p = Damage dt amount sp p ep NoDamageEffect
|
||||
-- where
|
||||
-- sp = _ptPos pt
|
||||
-- ep = sp +.+ _ptVel pt
|
||||
|
||||
moveStaticBall :: World -> Particle -> (World, Maybe Particle)
|
||||
moveStaticBall = moveFlamelet
|
||||
|
||||
-- | Note damgeInRadius by itself never destroys the particle
|
||||
damageInRadius :: Float -> Particle -> World -> World
|
||||
damageInRadius size pt = damageInArea isClose closeWls pt
|
||||
@@ -136,20 +103,6 @@ makeGasCloud pos vel w = w
|
||||
(col, g) = runState (takeOne [green,yellow]) $ _randGen w
|
||||
{- Attach poison cloud damage to creatures near cloud. -}
|
||||
|
||||
incBall :: RandomGen g => Point2 -> State g Particle
|
||||
incBall p = do
|
||||
rot <- state $ randomR (0,3)
|
||||
return PtIncBall
|
||||
{ _ptUpdate = moveFlamelet
|
||||
, _ptVel = 0
|
||||
, _ptColor = red
|
||||
, _ptPos = p
|
||||
, _ptWidth = 3
|
||||
, _ptTimer = 20
|
||||
, _ptHitEff = expireAndDamage $ simpleDam FLAMING 1
|
||||
, _ptZ = 20
|
||||
, _ptRot = rot
|
||||
}
|
||||
|
||||
{- Update of a flamelet.
|
||||
Applies movement and attaches damage to nearby creatures. -}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{- |
|
||||
Find which objects lie upon a line.
|
||||
-}
|
||||
@@ -7,6 +7,8 @@ module Dodge.WorldEvent.ThingsHit
|
||||
, thingHit
|
||||
, thingHitFilt
|
||||
, thingsHitExceptCr
|
||||
, crsHitRadial
|
||||
, wlsHitRadial
|
||||
)
|
||||
where
|
||||
import Dodge.Data
|
||||
@@ -15,6 +17,7 @@ import Dodge.Zone
|
||||
import Geometry
|
||||
|
||||
--import Data.Maybe
|
||||
import Data.Functor
|
||||
import Data.Bifunctor
|
||||
import StreamingHelp
|
||||
import qualified Streaming.Prelude as S
|
||||
@@ -66,3 +69,19 @@ wlsHit sp ep
|
||||
| otherwise = sortStreamOn (dist sp . fst)
|
||||
. overlapSegWalls sp ep
|
||||
. wlsNearSeg sp ep
|
||||
|
||||
wlsHitRadial :: Point2 -> Float -> World -> StreamOf (Point2, Wall)
|
||||
wlsHitRadial p r = S.mapMaybe f . wlsInsideCirc p r
|
||||
where
|
||||
f wl = uncurry (intersectSegSeg p (p -.- r *.* v)) (_wlLine wl) <&> (,wl)
|
||||
where
|
||||
v = normalizeV $ vNormal $ uncurry (-.-) $ _wlLine wl
|
||||
|
||||
crsHitRadial :: Point2 -> Float -> World -> StreamOf (Point2, Creature)
|
||||
crsHitRadial p r = S.mapMaybe f . crsInsideCirc p r
|
||||
where
|
||||
f cr
|
||||
| dist cpos p <= r = Just (cpos +.+ r *.* normalizeV (p -.- cpos), cr)
|
||||
| otherwise = Nothing
|
||||
where
|
||||
cpos = _crPos cr
|
||||
|
||||
Reference in New Issue
Block a user