packages feed

edge-0.8: Item.hs

module Item where

import Data.WrapAround
import Moving
import Animation
import Data.Maybe
import Graphics.Gloss.Data.Picture
import Graphics.Gloss.Data.Color
import ResourceTracker
import System.Random

data ItemType = Health
                | FourWay
                | Cannon
                | Spread
                | RapidFire
                | Nuke
  deriving (Show)

data Item = Item ItemType ResourceTracker WrapPoint
  deriving (Show)

instance Colliding Item where
  collisionRadius _ = 11.0

instance Locatable Item where
  center (Item _ _ a) = a

instance Moving Item where

  velocity _ = (0.0, 0.0)

instance Animation Item where
  image (Item ty rt _) _ = fromMaybe
                            (Scale 0.20 0.20
                              (Color white
                              (Text "Error! Missing image!")))
                            (getImage rt pic)
    where pic = case ty of
                  Health -> "item-health.bmp"
                  FourWay -> "item-fourway.bmp"
                  Cannon -> "item-cannon.bmp"
                  Spread -> "item-spread.bmp"
                  RapidFire -> "item-rapidfire.bmp"
                  Nuke -> "item-nuke.bmp"

randomItemType :: IO (ItemType)
randomItemType = do let min = (0 :: Int)
                    let max = (5 :: Int)
                    r <- randomRIO (min, max)
                    return $
                      case r of
                        0 -> Health
                        1 -> FourWay
                        2 -> Cannon
                        3 -> Spread
                        4 -> RapidFire
                        otherwise -> Nuke