Improve static bullets

This commit is contained in:
2022-07-19 13:15:13 +01:00
parent 54ba0fbedc
commit 0a7922ec5e
19 changed files with 287 additions and 134 deletions
+63
View File
@@ -0,0 +1,63 @@
module Dodge.EnergyBall where
import Dodge.Data
import Dodge.DamageCircle
import Dodge.LightSource
import Geometry
import Picture
import LensHelp
import RandomHelp
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
& energyBalls .:~ EnergyBall
{ _ebVel = vel
, _ebColor = red
, _ebPos = V2 x y
, _ebWidth = size
, _ebTimer = time
, _ebEff = (FLAMING,1)
, _ebZ = z
, _ebRot = rot
}
where
(rot ,g) = randomR (0,3) $ _randGen w
moveEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
moveEnergyBall w eb
| _ebTimer eb <= 0 = ( w, Nothing)
| otherwise =
( ebFlicker eb $ uncurry (damageCircle 5 (_ebPos eb)) (_ebEff eb) w
, Just $ eb & ebTimer -~ 1 & ebPos .+.+~ _ebVel eb & ebVel .*.*~ 0.9
)
incBallAt :: Point2 -> World -> World
incBallAt p w = w & energyBalls .:~ theincball
& randGen .~ g
where
(theincball,g) = runState thestate (_randGen w)
thestate = do
rot <- state $ randomR (0,3)
return EnergyBall
{ _ebVel = 0
, _ebColor = red
, _ebPos = p
, _ebWidth = 3
, _ebTimer = 20
, _ebEff = (FLAMING,1)
, _ebZ = 20
, _ebRot = rot
}
ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
| _ebTimer pt `mod` 7 == 0 = tempLightSources
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
| otherwise = id