module Asteroid where import Animation import Updating import Graphics.Gloss.Data.Picture import Graphics.Gloss.Data.Color import qualified Moving as M import Data.WrapAround import ResourceTracker import GHC.Float import Combat import Data.Maybe import SpaceJunk asteroidRadius = 15.0 damageEnergy' = 100.0 data Asteroid = Asteroid { location :: WrapPoint , idealTargetLocation :: Maybe WrapPoint , velocity :: (Double, Double) , wrapMap :: WrapMap , animDefault0 :: Picture } new :: ResourceTracker -> WrapMap -> WrapPoint -> (Double, Double) -> Asteroid new rt wmap location velocity = let pic = fromMaybe (Scale 0.20 0.20 (Color white (Text "Error! Missing image!"))) (getImage rt "asteroid.bmp") in Asteroid { location = location , velocity = velocity , wrapMap = wmap , idealTargetLocation = Nothing , animDefault0 = pic } instance Animation Asteroid where image self _ = animDefault0 self instance M.Locatable Asteroid where center = location instance M.Moving Asteroid where velocity = velocity instance M.Colliding Asteroid where collisionRadius _ = asteroidRadius instance InternallyUpdating Asteroid where preUpdate asteroid t = updateIdealTargetLocation t asteroid postUpdate asteroid t = let location' = fromMaybe (location asteroid) (idealTargetLocation asteroid) in asteroid { location = location' , idealTargetLocation = Nothing } updateIdealTargetLocation t asteroid = asteroid { idealTargetLocation = Just (M.idealNewLocation (wrapMap asteroid) (location asteroid) (velocity asteroid) t) } instance Damageable Asteroid where inflictDamage = const instance Damaging Asteroid where damageEnergy _ = damageEnergy'