--{-# LANGUAGE TupleSections #-}
{- Bullet update.  -}
module Dodge.Particle.Bullet.Update
    ( mvBullet
    ) where
import Dodge.Data
--import Dodge.Base
import Dodge.WorldEvent.ThingsHit
--import Picture
import Geometry
import LensHelp

import Data.Bifunctor
{- Update for a generic bullet.  -}
mvBullet :: World -> Particle -> (World, Maybe Particle)
mvBullet w bt' 
    | t <= 0 || magV (_ptVel bt) < 1 = (w,Nothing)
    | otherwise = second (fmap dodrag) $ 
        hiteff bt (thingsHitExceptCr mcr p (p +.+ vel) w) w
  where
    bt = foldr (\mg b -> _mgField mg mg b) bt' $ _magnets w
    dodrag = ptVel .*.*~ drag
    drag = _btDrag bt
    mcr     = _ptCrIgnore bt
    (p:_)   = _ptTrail bt
    vel     = _ptVel bt
    hiteff  = _ptHitEff bt
    t       = _ptTimer bt
