module Dodge.Particle.Spark ( colSpark , colSparkRandDir , createBarrelSpark , randColDirTimeSpark ) where import Dodge.Data import Dodge.Particle.HitEffect.ExpireAndDamage import Dodge.Particle.Damage --import Dodge.Particle.Bullet.HitEffect import Dodge.Particle.Bullet.Update --import Dodge.WorldEvent.HitEffect import Color import Geometry import LensHelp import Control.Monad.State import System.Random --import Control.Lens -- TODO remove/simplify this function createBarrelSpark :: Point2 -> Float -> Int -> Int -> World -> World createBarrelSpark pos dir time colid = instantParticles .:~ PtSpark { _ptUpdate = mvSpark , _ptVel = rotateV dir (V2 5 0) , _ptDrag = 0.9 , _ptColor = numColor colid , _ptTrail = [pos] , _ptWidth = 1 , _ptTimer = time , _ptHitEff = expireAndDamage basicSparkDams } colSpark :: Int -> Color -> Point2 -> Float -> World -> World colSpark = colSparkRandDir 0.7 randColDirTimeSpark :: State StdGen Color -> State StdGen Float -> State StdGen Int -> Point2 -> World -> World randColDirTimeSpark randcol randdir randtime pos w = w & instantParticles .:~ spark & randGen .~ g where ((col,dir,time),g) = (`runState` _randGen w) $ do c <- randcol d <- randdir t <- randtime return (c,d,t) spark = PtSpark { _ptUpdate = mvSpark , _ptDrag = 0.9 , _ptVel = rotateV dir (V2 5 0) , _ptColor = col , _ptTrail = [pos] , _ptWidth = 1 , _ptTimer = time , _ptHitEff = expireAndDamage basicSparkDams } colSparkRandDir :: Float -> Int -> Color -> Point2 -> Float -> World -> World colSparkRandDir randDir time col pos baseDir w = w & instantParticles .:~ spark & randGen .~ g where (a,g) = randomR (-randDir,randDir) $ _randGen w dir = a + baseDir spark = PtSpark { _ptUpdate = mvSpark , _ptDrag = 0.9 , _ptVel = rotateV dir (V2 5 0) , _ptColor = col , _ptTrail = [pos] , _ptWidth = 1 , _ptTimer = time , _ptHitEff = expireAndDamage basicSparkDams }