module Dodge.Particle.Update where
import Dodge.Data
import LensHelp
import Geometry

mvPt :: Particle -> Maybe Particle
mvPt pt = Just $ pt
    & ptTrail %~ f
    & ptTimer -~ 1
    & ptCrIgnore .~ Nothing
  where
    f trl = head trl +.+ _ptVel pt : trl

destroyAt :: Point2 -> Particle -> Maybe Particle
destroyAt hitp pt = Just $ pt 
    & ptUpdate .~ killBulletUpdate
    & ptTrail  .:~ hitp
    & ptTimer %~ (min 3 . subtract 1)

killBulletUpdate :: World -> Particle -> (World,Maybe Particle)
killBulletUpdate w pt 
    | _ptTimer pt <= 0 = (w,Nothing)
    | otherwise = (w
        , Just $ pt & ptTimer -~ 1
            & ptTrail %~ (\(x:xs) -> x:x:xs)
        )
