packages feed

astrds-0.1: src/StaticInterface.hs

module StaticInterface where

import qualified Graphics.UI.SDL as SDL
import qualified Graphics.UI.SDL.TTF as SDL
import qualified Graphics.UI.SDL.Mixer as SDL
import qualified Graphics.Rendering.OpenGL as GL
import qualified Data.Map as M
import System.Random

import States

import Pic
import Options
import Config

-- | Static data:
-- this should be viewed as an "internal" datatype
-- (used for rendering and input handling);
-- caveat: depends on SDL!
data Static = Static { images   :: Images
                     , fonts    :: Fonts
                     , sounds   :: Sounds
                     , options  :: Options
                     }


data Fonts = Fonts { font     :: SDL.Font
                   , bigfont  :: SDL.Font
                   }

data Images = Images { pl_image     :: SDLPic
                     , bg_image     :: SDLPic 
                     , rock_image   :: SDLPic
                     , coll_image   :: SDLPic
                     , overlay      :: SDLPic
                     }

data SDLPic = SDLPic { sdl_image :: GL.TextureObject
                     , sdl_dim   :: Dim
                     }

data SDLSprite a = SDLSprite   { sdl_sprite  :: SDLPic
                               , sdl_offsets :: M.Map a Int
                               , sdl_tiledim :: Dim
                               }

data SDLAnimation = SDLAnimation { sdl_an_sprite      :: SDLSprite Int
                                 , sdl_an_description :: Int -> Int
                                 }

sdlPicToSprite :: SDLPic -> SDLSprite ()
sdlPicToSprite pic@(SDLPic img dim) = SDLSprite pic (M.singleton () 0) dim

data Sounds = Sounds { bg_sound :: SDLSound 
                     }

data SDLSound = SDLSound { sdl_chunk :: SDL.Chunk }

emptySounds :: Sounds
emptySounds = error "audio turned off -- therefore, audio is not accessible"

------------------------------------------------------------------------------
-- * All the images (abstractly, not as SDL images)
------------------------------------------------------------------------------

picData :: FilePath -> (Int, Int) -> IO Pic
picData f d =
  do
    img <- getDataFileName f
    return $ Pic { picpath = img, picdim = d }

playerPic  = picData "pics/player.png"      (64,64)
rockPic    = picData "pics/rock.png"        (64,64)
collPic    = picData "pics/collectible.png" (64,64)
overlayPic = picData "pics/overlay.png"     (1600,1200)
bgPic      = picData "pics/background.png"  (800,600)

---------------------------------------------------------------------
-- * All the sounds (abstractly)
---------------------------------------------------------------------

type Sound = String -- ^ path to the sound data

bgSound :: IO Sound
bgSound  = getDataFileName "sound/background.ogg"