module Dodge.Particle.Bullet.Spawn
    ( aBulAt
    ) where
import Dodge.Data
import Dodge.Particle.Bullet.Draw
import Dodge.Particle.Bullet.Update
import Geometry
import Picture
import LensHelp

import Data.Maybe
import Data.Bifunctor

aBulAt
    :: Maybe Float    -- ^ Start velocity step factor
    -> (Particle -> Particle)
    -> Maybe Color
    -> Maybe Int -- ^ Pass-through creature id
    -> Point2   -- ^ Start position
    -> Point2  -- ^ Velocity
    -> Float    -- ^ Drag
    -> HitEffect 
    -> Float    -- ^ Bullet width
    -> Particle
aBulAt vfact updatemod mcol maycid pos vel drag hiteff width = BulletPt
    { _ptDraw = drawBul
    , _ptUpdate = theupdate
    , _ptVel  = fromMaybe 1 vfact *.* vel
    , _btDrag = drag
    , _ptColor = fromMaybe (V4 200 200 200 2) mcol
--    , _ptColor = V4 2 2 2 2
    , _ptTrail = [pos]
    , _ptCrIgnore = maycid
    , _ptWidth = width
    , _ptTimer = 100
    , _ptHitEff = hiteff
    }
  where
    theupdate = case vfact of
        Just _  -> \w -> resetVel . mvBullet w . updatemod
        Nothing -> \w -> mvBullet w . updatemod
    resetVel = second $ fmap $ (ptUpdate .~ (\w -> mvBullet w . updatemod)) . (ptVel .~ vel)
