packages feed

edge-0.8.16: Item.hs

module Item where

import Data.WrapAround (WP)
import Moving ( Moving (velocity)
              , Locatable (center)
              , Colliding (collisionRadius)
              )
import Animation ( Animation(..) )
import Data.Maybe (fromMaybe)
import Graphics.Gloss.Data.Picture ( Picture ( Scale
                                             , Color
                                             , Text
                                             )
                                   )
import Graphics.Gloss.Data.Color (white)
import ResourceTracker ( RT
                       , getImage
                       , protectedGetImage
                       )
import System.Random (randomRIO)

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

data Item = Item ItemType RT WP
  deriving (Show)

instance Colliding Item where
  collisionRadius _ = 11.0

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

instance Moving Item where

  velocity _ = (0, 0)

instance Animation Item where
  image (Item a b _) _ = protectedGetImage b $
                           case a 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 = do r <- randomRIO (0, 5) :: IO Int
                    return $
                      case r of
                        0 -> Health
                        1 -> FourWay
                        2 -> Cannon
                        3 -> Spread
                        4 -> RapidFire
                        otherwise -> Nuke