module Dodge.Particle.HitEffect
    ( penWalls
    , module Dodge.Particle.HitEffect.ExpireAndDamage
    ) where
import Dodge.Data
import Dodge.Particle.Update
import Dodge.Particle.HitEffect.ExpireAndDamage
import Geometry

import Data.Bifunctor
type HitCreatureEffect   = Particle -> Point2 -> Creature   -> World -> World
type HitWallEffect       = Particle -> Point2 -> Wall       -> World -> World

penWalls 
    :: HitCreatureEffect 
    -> HitWallEffect 
    -> Particle 
    -> [(Point2, Either Creature Wall)] 
    -> World 
    -> (World, Maybe Particle)
penWalls crEff wlEff pt hitThings w = case hitThings of
    []              -> (              w, mvPt pt)
    ((p,Left cr):_) -> (crEff pt p cr w, destroyAt p pt)
    ((p,Right wl):hs) | _wlFireThrough wl 
                    -> first (wlEff pt p wl) $ penWalls crEff wlEff pt hs w
    ((p,Right wl):_) -> (wlEff pt p wl w, destroyAt p pt)
