{-| Module : Projectile.SWSide Description : Growing super weapon projectile Copyright : (c) Christopher Howard, 2016 License : GPL-3 Maintainer : ch.howard@zoho.com -} module Projectile.SWSide ( SWSide(..) , new , prj ) where import Prelude (min, (+), (*), Maybe(..), (-), ($), cos, (||), (.), Double, Bool(..), sin, max) import Graphics.Gloss.Data.Picture ( Picture(Circle, Color) ) import Graphics.Gloss.Data.Color ( cyan ) import Data.WrapAround ( WP, WM, distance ) import GHC.Float ( double2Float ) import Combat import Animation import Updating import qualified Moving as M ( Colliding(..), Moving(..), Locatable(..), newLocation ) import Common import Math velocityC = 700.0 rangeC = 1000.0 integrityMax = 60.0 damE = 3 radiusGrowth = 30 data SWSide = SWSide { velocity :: Velocity , center :: WP , rangeLeft :: Double , wrapMap :: WM , impacted :: Bool , clock :: Time , integrity :: Double , radius :: Double } new a b c (d, e) = SWSide { velocity = (x + d, y + e) , center = c , rangeLeft = rangeC , wrapMap = a , impacted = False , clock = 0.0 , integrity = integrityMax , radius = 2.0 } where (x, y) = appPair ((* velocityC) . ($ b)) (cos, sin) instance Animation SWSide where image s t = Color cyan (Circle (double2Float (radius s))) instance M.Colliding SWSide where collisionRadius = radius instance M.Moving SWSide where velocity = velocity instance M.Locatable SWSide where center = center expirationFormula s = f rangeLeft || f integrity where f g = (zeroOrLess . g) s instance SimpleTransient SWSide where expired = expirationFormula instance InternallyUpdating SWSide where preUpdate s t = s { clock = clock s + t } postUpdate s t = s { center = a, rangeLeft = r, radius = q } where a = M.newLocation (wrapMap s) (center s) (velocity s) t r = max 0 (rangeLeft s - Data.WrapAround.distance (wrapMap s) (center s) a) q = min 128.0 ((radius s) + radiusGrowth * t) instance Damaging SWSide where damageEnergy _ = damE instance Transient SWSide where expired' s = if expirationFormula s then Just [] else Nothing instance Damageable SWSide where inflictDamage s d = s { integrity = integrity s - d } -- | Func abstracting construction of 'SWSide' projectile prj :: (M.Moving a) => a -- ^ object receiving projectile -> (a -> WM) -- ^ func which retrieves WM from object -> Angle -- ^ firing angle -> Projectile prj a f b = Projectile (new (f a) b (M.center a) (M.velocity a))