module Dodge.Particle.Bullet.Spawn
    where
import Dodge.Data
import Dodge.Particle.Bullet.Draw
import Dodge.Particle.Bullet.Update
import Geometry
import Picture

import Control.Lens
import Data.Bifunctor

aGenBulAt
    :: Maybe Int -- ^ Pass-through creature id
    -> Point2   -- ^ Start position
    -> Point2  -- ^ Velocity
    -> HitEffect 
    -> Float    -- ^ Bullet width
    -> Particle
aGenBulAt maycid pos vel hiteff width = BulletPt
    { _ptDraw = drawBul
    , _ptUpdate' = mvGenBullet
    , _btVel' = vel
    , _btColor' = V4 2 2 2 2
    , _btTrail' = [pos]
    , _btPassThrough' = maycid
    , _btWidth' = width
    , _btTimer' = 100
    , _btHitEffect' = hiteff
    }
aDelayedBulAt
    :: Float    -- ^ Start velocity step factor
    -> Maybe Int -- ^ Pass-through creature id
    -> Point2   -- ^ Start position
    -> Point2  -- ^ Velocity
    -> HitEffect 
    -> Float    -- ^ Bullet width
    -> Particle
aDelayedBulAt vfact maycid pos vel hiteff width = BulletPt
    { _ptDraw = drawBul
    , _ptUpdate' = \w -> resetVel . mvGenBullet w
    , _btVel' = vfact *.* vel
    , _btColor' = V4 2 2 2 2
    , _btTrail' = [pos]
    , _btPassThrough' = maycid
    , _btWidth' = width
    , _btTimer' = 100
    , _btHitEffect' = hiteff
    }
  where
    resetVel = second $ fmap $ (ptUpdate' .~ mvGenBullet) . (btVel' .~ vel)

aCurveBulAt 
    :: Maybe Int -- ^ Pass-through creature id
    -> Color 
    -> Point2   -- ^ Start position
    -> Point2   -- ^ Control position
    -> Point2   -- ^ Target position
    -> HitEffect 
    -> Float    -- ^ Bullet width
    -> Particle
aCurveBulAt maycid col pos control targ hiteff width = BulletPt
    { _ptDraw = drawBul
    , _ptUpdate' = \w -> mvGenBullet w . setVel
    , _btVel' = V2 0 0
    , _btColor' = col
    , _btTrail' = [pos]
    , _btPassThrough' = maycid
    , _btWidth' = width
    , _btTimer' = 100
    , _btHitEffect' = hiteff
    }
  where 
    setVel pt = pt & btVel' .~ bf (fromIntegral $ _btTimer' pt - 1) -.- bf (fromIntegral $ _btTimer' pt)
    bf t = bQuadToF (pos,control,targ) $ (100 - t) * 0.05
