Files
loop/src/Dodge/EnergyBall.hs
T

100 lines
2.5 KiB
Haskell

module Dodge.EnergyBall
( updateEnergyBall
, incBallAt
, makeFlashBall
, makeFlamelet
) where
import Dodge.DamageCircle
import Dodge.Data.World
import Dodge.LightSource
import Geometry
import LensHelp
import Picture
import RandomHelp
makeFlamelet ::
-- | Position
Point2 ->
-- | z position
Float ->
-- | Velocity
Point2 ->
-- | Size
Float ->
-- | Timer
Int ->
World ->
World
makeFlamelet (V2 x y) z vel size time w =
w
& randGen .~ g
& cWorld . lWorld . 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
updateEnergyBall :: World -> EnergyBall -> (World, Maybe EnergyBall)
updateEnergyBall 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 & cWorld . lWorld . 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
}
makeFlashBall :: Point2 -> World -> World
makeFlashBall p w =
w & cWorld . lWorld . energyBalls .:~ theincball
& randGen .~ g
where
(theincball, g) = runState thestate (_randGen w)
thestate = do
rot <- state $ randomR (0, 3)
return
EnergyBall
{ _ebVel = 0
, _ebColor = yellow
, _ebPos = p
, _ebWidth = 3
, _ebTimer = 20
, _ebEff = (LASERING, 1)
, _ebZ = 20
, _ebRot = rot
}
ebFlicker :: EnergyBall -> World -> World
ebFlicker pt
| _ebTimer pt `mod` 7 == 0 =
cWorld . lWorld . tempLightSources
.:~ tlsTimeRadColPos 1 70 (0.5 *.*.* xyzV4 (_ebColor pt)) (addZ 20 $ _ebPos pt)
| otherwise = id