packages feed

Eternal10Seconds-0.1: Title.hs

module Title where

import Monad
import qualified Graphics.UI.SDL as SDL
import Resource

-- タイトル画面
data Title = Title MenuIndex

initTitle = Title 0

type MenuIndex = Int
nextMenu index = mod (index + 1) 3
prevMenu index = mod (index - 1) 3

cursorRect :: MenuIndex -> SDL.Rect
cursorRect i = SDL.Rect (300+50*i) (400+50*i) 50 50

titlePaint = (("./resource/image/title.bmp", Nothing), Nothing)
titleStartPaint = (("./resource/image/title_start.bmp", Nothing), Just (SDL.Rect 350 400 200 50))
titleScorePaint = (("./resource/image/title_score.bmp", Nothing), Just (SDL.Rect 400 450 200 50))
titleQuitPaint = (("./resource/image/title_quit.bmp", Nothing), Just (SDL.Rect 450 500 200 50))
cursorTip = ("./resource/image/cursor.bmp", Nothing)
cursorStart = Just (SDL.Rect 300 400 50 50)
cursorEnd= Just (SDL.Rect 350 450 50 50)

titlePaints = [titlePaint, titleStartPaint, titleScorePaint, titleQuitPaint]
titleTips = [cursorTip]
titleImgFiles = (map fst titleTips) ++ (map (fst.fst) titlePaints)

-- 描画
renderTitle :: Title -> SDL.Surface -> Resource -> IO ()
renderTitle (Title i) surf res = do
    haltSound
    mapM_ (renderPaint res surf) titlePaints
    renderPaint res surf (cursorTip, Just $ cursorRect i)
    return ()

-- リソースの更新
addTitleResource :: Resource -> IO Resource
addTitleResource res = foldM addImageResource res titleImgFiles