packages feed

edge-0.8: BigAsteroid.hs

module BigAsteroid 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

asteroidRadius = 30.0

punch = 100.0

data BigAsteroid =
  BigAsteroid { location :: WrapPoint
           , idealTargetLocation :: Maybe WrapPoint
           , velocity :: (Double, Double)
           , wrapMap :: WrapMap
           , animDefault0 :: Picture
           }

new :: ResourceTracker -> WrapMap -> WrapPoint -> (Double, Double) -> BigAsteroid
new rt wmap location velocity =
  let pic = fromMaybe
              (Scale 0.20 0.20
                (Color white
                  (Text "Error! Missing image!")))
                    (getImage rt "asteroidbig.bmp") in
  BigAsteroid { location = location
  	   , velocity = velocity
           , wrapMap = wmap
           , idealTargetLocation = Nothing
           , animDefault0 = pic
          }


instance Animation BigAsteroid where
  image self _ = animDefault0 self

instance M.Locatable BigAsteroid where
  center = location

instance M.Moving BigAsteroid where
  velocity = velocity

instance M.Colliding BigAsteroid where
  collisionRadius _ = asteroidRadius

instance InternallyUpdating BigAsteroid 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 BigAsteroid where

  inflictDamage = const


instance Damaging BigAsteroid where

  damageEnergy _ = punch