Changeset 20925

Show
Ignore:
Timestamp:
10/07/08 20:42:00 (3 months ago)
Author:
mokehehe
Message:

ソース整理

Location:
lang/haskell/nario
Files:
17 modified

Legend:

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

    r20811 r20925  
    11{-# OPTIONS_GHC -fglasgow-exts #-} 
     2-- -*- mode: haskell; Encoding: UTF-8 -*- 
     3 
     4-- ゲーム内に登場するオブジェクト 
    25 
    36module Actor ( 
     
    1114import Multimedia.SDL (Surface) 
    1215 
     16import AppUtil (ImageResource, Rect) 
    1317import Event (Event) 
    14 import AppUtil (ImageResource, Rect) 
    1518import Field (Field) 
    1619import Player (Player) 
     
    3033        onHit pl ac = (pl, Nothing, []) 
    3134 
    32 -- ============================================================================ 
    3335 
    3436---- 
  • lang/haskell/nario/Actor/AnimBlock.hs

    r20811 r20925  
    1 -- -*- mode: haskell; Encoding: UTF-8 -*- 
     1-- -*- mode: haskell; Encoding: UTF-8 -*- 
    22-- ブロックを叩いたときのバウンド演出 
    33 
     
    66) where 
    77 
    8 import Multimedia.SDL hiding (Event) 
     8--import Multimedia.SDL hiding (Event) 
    99 
    1010import Actor (Actor(..)) 
     11import AppUtil (cellCrd, putimg) 
    1112import Const 
    12 import AppUtil 
    13 import Images 
    14 import Field 
    15 import Event 
     13import Field (Cell, chr2img) 
     14import Event (Event(..)) 
    1615 
    1716 
     
    3332                        y' = y self + vy' 
    3433                        self' = self { vy = vy', y = y' } 
    35                         ev' = if (bDead self') 
     34                        ev' = if bDead self' 
    3635                                then [EvSetField (cellCrd $ x self) (startcy self) $ chr self] 
    3736                                else [] 
    3837 
    3938        render self imgres scrx sur = do 
    40                 blitSurface (getImageSurface imgres $ chr2img $ chr self) Nothing sur (pt (x self `div` one - scrx) (y self `div` one - 8)) 
     39                putimg sur imgres (chr2img $ chr self) (x self `div` one - scrx) (y self `div` one - 8) 
    4140                return () 
    4241 
  • lang/haskell/nario/Actor/BrokenBlock.hs

    r20825 r20925  
    99 
    1010import Actor (Actor(..)) 
    11 import AppUtil 
    1211import Const 
     12import AppUtil (putimg) 
    1313import Images 
    1414 
     
    2525 
    2626        render self imgres scrx sur = do 
    27                 blitSurface (getImageSurface imgres ImgBroken) Nothing sur (pt (x self `div` one - 4 - scrx) (y self `div` one - 4 - 8)) 
     27                putimg sur imgres ImgBroken (x self `div` one - 4 - scrx) (y self `div` one - 4 - 8) 
    2828                return () 
    2929 
  • lang/haskell/nario/Actor/CoinGet.hs

    r20811 r20925  
    1 -- -*- mode: haskell; Encoding: UTF-8 -*- 
     1-- -*- mode: haskell; Encoding: UTF-8 -*- 
    22-- コインを取ったときの演出コイン 
    33 
     
    99 
    1010import Actor (Actor(..)) 
    11 import AppUtil 
     11import AppUtil (putimg) 
    1212import Const 
    1313import Images 
    14 import Event 
     14import Event (Event(..)) 
    1515 
    1616 
     
    3333 
    3434        render self imgres scrx sur = do 
    35                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt (sx self - scrx) (y self `div` one - 8)) 
     35                putimg sur imgres imgtype (sx self - scrx) (y self `div` one - 8) 
    3636                return () 
    3737                where 
  • lang/haskell/nario/Actor/Flower.hs

    r20811 r20925  
    66) where 
    77 
    8 import Multimedia.SDL (blitSurface, pt) 
     8--import Multimedia.SDL (itSurface, pt) 
    99 
    1010import Actor (Actor(..)) 
    1111import Const 
    1212import Util (sgn) 
    13 import AppUtil (getImageSurface, cellCrd, Rect(..)) 
     13import AppUtil (cellCrd, Rect(..), putimg) 
    1414import Images 
    15 import Field 
    1615import Player (PlayerType(..), getPlayerType, setPlayerType, addScore) 
    1716import Event (Event(..)) 
     
    2928 
    3029        render self imgres scrx sur = do 
    31                 blitSurface (getImageSurface imgres ImgFlower) Nothing sur (pt ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - 15 - 8)) 
     30                putimg sur imgres ImgFlower ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - 15 - 8) 
    3231                return () 
    3332 
  • lang/haskell/nario/Actor/Kinoko.hs

    r20825 r20925  
    66) where 
    77 
    8 import Multimedia.SDL (blitSurface, pt) 
     8--import Multimedia.SDL (blitSurface, pt) 
    99 
    1010import Actor (Actor(..)) 
    1111import Actor.Common (updateActorBase) 
     12import AppUtil (Rect(..), putimg) 
    1213import Const 
    13 import AppUtil (getImageSurface, Rect(..)) 
    1414import Images 
    1515import Player (PlayerType(..), getPlayerType, setPlayerType, addScore) 
     
    3333 
    3434        render self imgres scrx sur = do 
    35                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8)) 
     35                putimg sur imgres imgtype ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    3636                return () 
    3737                where 
  • lang/haskell/nario/Actor/Koura.hs

    r20825 r20925  
    66) where 
    77 
    8 import Multimedia.SDL (blitSurface, pt) 
     8--import Multimedia.SDL (blitSurface, pt) 
    99 
    1010import Actor (Actor(..), ActorWrapper(..)) 
    1111import Actor.Common (updateActorBase, stamp) 
     12import AppUtil (Rect(..), putimg) 
    1213import Const 
    13 import AppUtil (getImageSurface, Rect(..)) 
    1414import Images 
    1515import Player (getPlayerX, stampPlayer, setPlayerDamage, addScore) 
     
    4444 
    4545        render self imgres scrx sur = do 
    46                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8)) 
     46                putimg sur imgres imgtype ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    4747                return () 
    4848                where 
  • lang/haskell/nario/Actor/Kuribo.hs

    r20825 r20925  
    66) where 
    77 
    8 import Multimedia.SDL (blitSurface, pt) 
     8--import Multimedia.SDL (blitSurface, pt) 
    99 
    1010import Actor (Actor(..), ActorWrapper(..)) 
    1111import Actor.Common (updateActorBase, stamp) 
     12import AppUtil (Rect(..), putimg) 
    1213import Const 
    13 import AppUtil (getImageSurface, Rect(..)) 
    1414import Images 
    1515import Player (setPlayerDamage, stampPlayer, addScore) 
     
    3333 
    3434        render self imgres scrx sur = do 
    35                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8)) 
     35                putimg sur imgres imgtype (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8) 
    3636                return () 
    3737                where 
     
    6767 
    6868        render self imgres scrx sur = do 
    69                 blitSurface (getImageSurface imgres ImgKuriDead) Nothing sur (pt (sx self - scrx) (sy self - 7 - 8)) 
     69                putimg sur imgres ImgKuriDead (sx self - scrx) (sy self - 7 - 8) 
    7070                return () 
    7171 
  • lang/haskell/nario/Actor/Nokonoko.hs

    r20825 r20925  
    66) where 
    77 
    8 import Multimedia.SDL (blitSurface, pt) 
     8--import Multimedia.SDL (blitSurface, pt) 
    99 
    1010import Actor (Actor(..), ActorWrapper(..)) 
    1111import Actor.Common (updateActorBase, stamp) 
    1212import Actor.Koura 
     13import AppUtil (Rect(..), putimg) 
    1314import Const 
    14 import AppUtil (getImageSurface, Rect(..)) 
    1515import Images 
    1616import Player (setPlayerDamage, stampPlayer, addScore) 
     
    3434 
    3535        render self imgres scrx sur = do 
    36                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8)) 
     36                putimg sur imgres imgtype (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8) 
    3737                return () 
    3838                where 
  • lang/haskell/nario/Actor/ScoreAdd.hs

    r20811 r20925  
    66) where 
    77 
    8 import Multimedia.SDL hiding (Event) 
     8--import Multimedia.SDL hiding (Event) 
    99 
    1010import Actor (Actor(..)) 
    11 import AppUtil 
     11import AppUtil (putimg) 
    1212import Const 
    1313import Images 
     
    2727 
    2828        render self imgres scrx sur = do 
    29                 blitSurface (getImageSurface imgres imgtype) Nothing sur (pt (sx self - scrx) (sy self)) 
     29                putimg sur imgres imgtype (sx self - scrx) (sy self) 
    3030                return () 
    3131                where 
  • lang/haskell/nario/AppUtil.hs

    r20673 r20925  
    11module AppUtil where 
    22 
    3 import Multimedia.SDL (Surface, SDLKey(..), loadBMP, freeSurface, surfacePixelFormat, displayFormat, pfPalette, setColorKey, SurfaceFlag(..)) 
     3import Multimedia.SDL (Surface, SDLKey(..), loadBMP, freeSurface, surfacePixelFormat, displayFormat, pfPalette, setColorKey, SurfaceFlag(..), blitSurface, pt) 
    44import Data.Maybe (fromJust) 
    55 
     
    6969getImageSurface imgres = fromJust . flip lookup imgres 
    7070 
     71putimg :: Surface -> ImageResource -> ImageType -> Int -> Int -> IO () 
     72putimg sur imgres imgtype x y = do 
     73        blitSurface (getImageSurface imgres imgtype) Nothing sur (pt x y) 
     74        return () 
     75 
    7176 
    7277-- 固定座標系からセル座標系に 
  • lang/haskell/nario/Field.hs

    r20670 r20925  
    9494                        | c `elem` " *" = return () 
    9595                        | otherwise             = putchr x y c >> return () 
    96                 putchr x y c = blitSurface (getImageSurface imgres $ chr2img c) Nothing sur $ pt (x*chrSize - rx) (y*chrSize - 8) 
     96                putchr x y c = putimg sur imgres (chr2img c) (x*chrSize - rx) (y*chrSize - 8) 
    9797 
    9898                -- 表示される部分だけ取り出す 
  • lang/haskell/nario/Font.hs

    r20670 r20925  
     1-- -*- mode: haskell; Encoding: UTF-8 -*- 
    12-- Bitmap font 
    23module Font ( 
     4        Font(..), 
    35        fontPut, 
    46        fontPutc 
    57) where 
    68 
    7 import Multimedia.SDL 
    8 import Control.Monad 
    9 import Data.Char 
     9import Multimedia.SDL (blitSurface, pt, Rect(..), Surface) 
     10import Control.Monad (zipWithM_) 
     11import Data.Char (ord) 
    1012 
    11 fontWidth = 8 
    12 fontHeight = 8 
    13 fontXN = 16 
     13data Font = Font { 
     14        fontSurface :: Surface, 
     15        fontWidth :: Int, 
     16        fontHeight :: Int, 
     17        fontXN :: Int 
     18        } 
     19 
    1420 
    1521-- 文字列表示 
    16 fontPut sur imgsur x y str = zipWithM_ (\i c -> fontPutc sur imgsur i y c) [x..] str 
     22fontPut font sur x y str = zipWithM_ (\i c -> fontPutc font sur i y c) [x..] str 
    1723 
    1824-- 1文字表示 
    19 fontPutc sur imgsur x y c = do 
    20         blitSurface imgsur (Just rc) sur pos 
     25fontPutc font sur x y c = do 
     26        blitSurface (fontSurface font) (Just rc) sur pos 
    2127        where 
    22                 pos = pt (x * fontWidth) (y * fontHeight) 
     28                pos = pt (x * (fontWidth font)) (y * (fontHeight font)) 
    2329                ic = ord c - ord ' ' 
    24                 u = (ic `mod` fontXN) * fontWidth 
    25                 v = (ic `div` fontXN) * fontHeight 
    26                 rc = Rect u v fontWidth fontHeight 
     30                u = (ic `mod` xn) * w 
     31                v = (ic `div` xn) * h 
     32                rc = Rect u v w h 
     33 
     34                xn = fontXN font 
     35                w = fontWidth font 
     36                h = fontHeight font 
  • lang/haskell/nario/Main.hs

    r20825 r20925  
    240240        return () 
    241241 
    242 tailN n = reverse . take n . reverse 
    243  
    244 deciWide w c n = tailN w $ replicate w c ++ show n 
    245  
    246242-- 情報描画 
    247243renderInfo :: GameGame -> ImageResource -> Scr 
    248244renderInfo gs imgres sur = do 
    249         puts 3 1 "NARIO" 
    250         puts 3 2 $ deciWide 6 '0' $ getPlayerScore (pl gs) 
    251         puts 11 2 ("?*" ++ deciWide 2 '0' (getPlayerCoin (pl gs))) 
     245        puts  3 1 "NARIO" 
     246        puts  3 2 $ deciWide 6 '0' $ getPlayerScore (pl gs) 
     247        puts 11 2 ("?*" ++ deciWide 2 '0' (getPlayerCoin $ pl gs)) 
    252248        puts 18 1 "WORLD" 
    253249        puts 19 2 "1-1" 
    254250        puts 25 1 "TIME" 
    255         puts 26 2 $ deciWide 3 '0' ((time gs + timeBase-1) `div` timeBase) 
    256  
    257         where 
    258                 puts = fontPut sur fontsur 
    259                 fontsur = getImageSurface imgres ImgFont 
     251        puts 26 2 $ deciWide 3 '0' $ (time gs + timeBase-1) `div` timeBase 
     252        where 
     253                puts = fontPut font sur 
     254                font = Font (getImageSurface imgres ImgFont) 8 8 16 
    260255 
    261256-- タイトル画面 
    262257renderTitle imgres sur = do 
    263         blitSurface (getImageSurface imgres ImgTitle) Nothing sur (pt (5*8) (3*8)) 
     258        putimg sur imgres ImgTitle (5*8) (3*8) 
    264259--      puts 13 14 "@1985 NINTENDO" 
    265         puts 9 17 "> 1 PLAYER GAME" 
    266 --      puts 9 19 "  2 PLAYER GAME" 
     260        puts  9 17 "> 1 PLAYER GAME" 
     261--      puts  9 19 "  2 PLAYER GAME" 
    267262        puts 12 22 "TOP- 000000" 
    268263        where 
    269                 puts = fontPut sur fontsur 
    270                 fontsur = getImageSurface imgres ImgFont 
     264                puts = fontPut font sur 
     265                font = Font (getImageSurface imgres ImgFont) 8 8 16 
  • lang/haskell/nario/Player.hs

    r20811 r20925  
    2626 
    2727import Util 
    28 import AppUtil (KeyProc, isPressed, PadBtn(..), cellCrd, KeyState(..), getImageSurface, Rect(..)) 
     28import AppUtil (KeyProc, isPressed, PadBtn(..), cellCrd, KeyState(..), getImageSurface, Rect(..), putimg) 
    2929import Const 
    3030import Images 
     
    120120moveX :: KeyProc -> Player -> Player 
    121121moveX kp self = 
    122         if (stand self) 
     122        if stand self 
    123123                then self' { lr = lr', pat = pat', anm = anm' } 
    124124                else self' 
     
    324324renderPlayer sur imgres scrx self = do 
    325325        if undeadCount self == 0 || (undeadCount self .&. 1) /= 0 
    326                 then blitSurface (getImageSurface imgres imgtype) Nothing sur pos >> return () 
     326                then putimg sur imgres imgtype sx posy 
    327327                else return () 
    328328        where 
    329                 pos = case pltype self of 
    330                         SmallNario      -> pt sx $ sy - chrSize + 1 
    331                         otherwise       -> pt sx $ sy - chrSize * 2 + 1 
     329                posy = case pltype self of 
     330                        SmallNario      -> sy - chrSize + 1 
     331                        otherwise       -> sy - chrSize * 2 + 1 
    332332                imgtype 
    333333                        | plstate self == Dead  = ImgNarioDead 
  • lang/haskell/nario/README.txt

    r20811 r20925  
    44 
    55を Haskell/HSDL で作る 
    6  
    7 HSDL 
    8 http://fxp.hp.infoseek.co.jp/haskell/HSDL/ 
    96 
    107 
     
    1512 
    1613        スペースキー, z 
    17                 Aボタン 
     14                ジャンプ(Aボタン) 
    1815 
    1916        シフトキー 
    20                 Bボタン 
     17                ダッシュ(Bボタン) 
    2118 
    2219        エスケープキー 
     
    4744 
    4845 ○実行 
    49         できた実行ファイルを入力、または 
     46        できた実行ファイルを起動する、または 
    5047        make run 
    5148 
  • lang/haskell/nario/Util.hs

    r20670 r20925  
    77replace ls i v = take i ls ++ [v] ++ drop  (i + 1) ls 
    88 
    9 -- 符号を返す 
     9-- けつの n 個取り出し 
     10lastN n xs = loop n [] xs 
     11        where 
     12                loop _ acc [] = acc 
     13                loop 0 acc (x:xs) = loop 0 (tail acc ++ [x]) xs 
     14                loop n acc (x:xs) = loop (n-1) (acc ++ [x]) xs 
     15 
     16-- 数値の符号を返す 
    1017sgn x 
    1118        | x > 0         = 1 
    1219        | x < 0         = -1 
    1320        | otherwise     = 0 
     21 
     22-- 10進数 n 桁文字列を返す 
     23deciWide n c = lastN n . (replicate n c ++) . show 
    1424 
    1525-- x に d を加算した結果が x0~x1 の範囲内を超えないようにする