Changeset 20397 for lang/haskell

Show
Ignore:
Timestamp:
10/01/08 22:17:57 (7 weeks ago)
Author:
mokehehe
Message:

画像定義ファイルを自動に作成するように

Location:
lang/haskell/nario
Files:
5 added
8 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Actor.hs

    r20243 r20397  
    55 
    66import Const 
     7import Images 
    78import Util 
     9import AppUtil 
    810import Event 
    911 
  • lang/haskell/nario/Const.hs

    r20243 r20397  
    1212gravity2 = one `div` 4 
    1313 
     14{- 
    1415-- 画像 
    1516data ImageType = 
     
    7980        ImgTitle 
    8081        ] 
     82-} 
  • lang/haskell/nario/Event.hs

    r20244 r20397  
    33 
    44import Const 
     5import Images 
    56import Field 
    67 
  • lang/haskell/nario/Field.hs

    r20244 r20397  
    1919 
    2020import Const 
     21import Images 
    2122import Util 
     23import AppUtil 
    2224 
    2325type Cell = Char 
  • lang/haskell/nario/Main.hs

    r20243 r20397  
    1212import Field 
    1313import Util 
     14import AppUtil 
    1415import Const 
     16import Images 
    1517import Font 
    1618import Event 
     
    9698process :: [[SDLKey]] -> IO [Scr] 
    9799process kss = do 
    98         imgres <- loadImageResource images 
     100        imgres <- loadImageResource imageTypes 
    99101        st <- initialState 
    100102        let scrs = map (\scr -> scr imgres) $ loop [] st kss 
  • lang/haskell/nario/Makefile

    r19868 r20397  
    2020doc: 
    2121        haddock -h -o man -l C:\\ghc\\haddock-2.0.0.0 -B c:\\ghc\\ghc-6.8.2 *.hs 
     22 
     23 
     24imgs: 
     25        runghc -itool tool/listup-imgs.hs data/img > Images.hs 
  • lang/haskell/nario/Player.hs

    r20244 r20397  
    1313 
    1414import Util 
     15import AppUtil 
    1516import SDLUtil 
    1617import Const 
     18import Images 
    1719import Field 
    1820import Event 
  • lang/haskell/nario/Util.hs

    r20243 r20397  
    11module Util where 
    2  
    3 import System.Time (getClockTime, diffClockTimes, noTimeDiff, tdMin, tdSec, tdPicosec) 
    4 import Control.Concurrent (threadDelay) 
    5 import Data.Maybe (fromJust) 
    6 import Multimedia.SDL 
    7  
    8 import Const 
    92 
    103 
     
    3427        | x < -d        = x + d 
    3528        | otherwise     = 0 
    36  
    37  
    38  
    39 -- キーボード処理 
    40  
    41 data PadBtn = 
    42         PadU | PadD | PadL | PadR | PadA | PadB 
    43         deriving (Eq, Show, Enum) 
    44  
    45 data KeyState = 
    46         Pushed | Pushing | Released | Releasing 
    47         deriving (Eq, Show) 
    48  
    49 isPressed Pushed  = True 
    50 isPressed Pushing = True 
    51 isPressed _       = False 
    52  
    53 type KeyProc = PadBtn -> KeyState 
    54  
    55 keyProc bef cur gk 
    56         | not bp && not cp = Releasing 
    57         | not bp && cp     = Pushed 
    58         | bp     && not cp = Released 
    59         | bp     && cp     = Pushing 
    60         where 
    61                 bp = any (flip elem bef) phykeys 
    62                 cp = any (flip elem cur) phykeys 
    63                 phykeys = mapPhyKey gk 
    64  
    65 mapPhyKey PadU = [SDLK_UP, SDLK_i] 
    66 mapPhyKey PadD = [SDLK_DOWN, SDLK_k] 
    67 mapPhyKey PadL = [SDLK_LEFT, SDLK_j] 
    68 mapPhyKey PadR = [SDLK_RIGHT, SDLK_l] 
    69 mapPhyKey PadA = [SDLK_SPACE, SDLK_z] 
    70 mapPhyKey PadB = [SDLK_LSHIFT, SDLK_RSHIFT] 
    71  
    72  
    73  
    74 -- 画像リソース 
    75 type ImageResource = [(ImageType, Surface)] 
    76  
    77  
    78 -- 画像リソース読み込み 
    79 loadImageResource :: [ImageType] -> IO ImageResource 
    80 loadImageResource = mapM load 
    81         where 
    82                 load imgtype = do 
    83                         sur <- loadBMP $ ("data/img/" ++) $ imageFn imgtype 
    84                         setNuki sur 
    85                         converted <- displayFormat sur 
    86                         freeSurface sur 
    87                         return (imgtype, converted) 
    88  
    89                 setNuki sur = do 
    90                         let fmt = surfacePixelFormat sur 
    91                         if not $ null $ pfPalette fmt 
    92                                 then setColorKey sur [SRCCOLORKEY] 0 >> return ()       -- パレット0番目をぬき色に 
    93                                 else return () 
    94  
    95 releaseImageResource :: ImageResource -> IO () 
    96 releaseImageResource = mapM_ (\(t, sur) -> freeSurface sur) 
    97  
    98 getImageSurface :: ImageResource -> ImageType -> Surface 
    99 getImageSurface imgres t = fromJust $ lookup t imgres 
    100  
    101  
    102 -- 固定座標系からセル座標系に 
    103 cellCrd :: Int -> Int 
    104 cellCrd x = x `div` (chrSize * one)