module Dodge.EnergyBall ( updateEnergyBall , incBallAt , makeFlashBall , makeFlamelet ) where import Dodge.Base.Collide import Data.Maybe import Dodge.DamageCircle import Dodge.Data.World import Geometry import LensHelp import Picture import RandomHelp makeFlamelet :: -- | Position Point2 -> -- | Velocity Point2 -> -- | Size Float -> -- | Timer Int -> World -> World makeFlamelet (V2 x y) 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 , Just $ eb & ebTimer -~ 1 & ebPos .~ bp & ebVel .~ 0.8 * bv ) where p = eb ^. ebPos + eb ^. ebVel (bp,bv) = fromMaybe (p,eb^.ebVel) $ bouncePoint (const True) 0 (eb ^. ebPos) p w 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 . lights .:~ LSParam (addZ 20 $ _ebPos pt) 70 (0.5 *.*.* xyzV4 (_ebColor pt)) | otherwise = id