Changeset 20661

Show
Ignore:
Timestamp:
10/04/08 07:57:29 (3 months ago)
Author:
mokehehe
Message:

スクロールで敵を出すように
ディレクトリ分割

Location:
lang/haskell/nario
Files:
3 added
1 removed
7 modified

Legend:

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

    r20641 r20661  
    11{-# OPTIONS_GHC -fglasgow-exts #-} 
    22 
    3 module Actor where 
     3module Actor ( 
     4        Actor (..), 
     5        ObjWrapper (..), 
     6        updateActors, 
     7        filterActors, 
     8        renderActors 
     9) where 
    410 
    5 import Multimedia.SDL hiding (Event) 
     11import Multimedia.SDL (Surface) 
    612 
    7 import Const 
    8 import Images 
    9 import Util 
     13import Event 
    1014import AppUtil 
    11 import Event 
    12 import Field 
     15 
    1316 
    1417class Actor a where 
     
    1922 
    2023-- ============================================================================ 
    21 -- AnimBlock 
    22 --      ブロックを叩いたときのバウンド演出 
    23  
    24 data AnimBlock = AnimBlock { 
    25         startcy :: Int, 
    26         x :: Int, 
    27         y :: Int, 
    28         vy :: Int, 
    29         chr :: Cell 
    30         } 
    31  
    32 instance Actor AnimBlock where 
    33         update self 
    34                 | not (bDead self)      = (self', ev') 
    35                 | otherwise                     = (self, []) 
    36  
    37                 where 
    38                         vy' = vy self + gravity 
    39                         y' = y self + vy' 
    40                         self' = self { vy = vy', y = y' } 
    41                         ev' = if (bDead self') 
    42                                 then [EvSetField (cellCrd $ x self) (startcy self) $ chr self] 
    43                                 else [] 
    44  
    45         render self imgres scrx sur = do 
    46                 blitSurface (getImageSurface imgres $ chr2img $ chr self) Nothing sur (pt ((x self) `div` one - scrx) ((y self) `div` one - 8)) 
    47                 return () 
    48  
    49         bDead self = vy self > 0 && y self >= startcy self * chrSize * one 
    50  
    51 newAnimBlock :: Int -> Int -> Cell -> AnimBlock 
    52 newAnimBlock cx cy c = 
    53         AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one, chr = cc } 
    54         where 
    55                 cc = case c of 
    56                         '?'     -> '#' 
    57                         x       -> x 
    58  
    59  
    60 -- ============================================================================ 
    6124 
    6225---- 
    63 data ObjWrapper = forall a. Actor a => ObjWrapper a     -- ݌^a͈̓͂잃NXDuckɐ 
     26data ObjWrapper = forall a. Actor a => ObjWrapper a     -- 存在型aの動く範囲を型クラスに制限 
    6427 
    6528updateActors :: [ObjWrapper] -> [(ObjWrapper, [Event])] 
  • lang/haskell/nario/Event.hs

    r20397 r20661  
    99                EvHitBlock ImageType Int Int 
    1010        |       EvSetField Int Int Cell 
     11        |       EvAppearEnemy Int Int Cell 
  • lang/haskell/nario/Images.hs

    r20534 r20661  
    11module Images (ImageType(..), imageTypes, imageFn) where 
    22import Maybe (fromJust) 
    3 data ImageType = ImgBlock1 | ImgBlock2 | ImgBlock3 | ImgBlock4 | ImgBlock5 | ImgCloud00 | ImgCloud01 | ImgCloud02 | ImgCloud10 | ImgCloud11 | ImgCloud12 | ImgDk00 | ImgDk01 | ImgDk10 | ImgDk11 | ImgFlag | ImgFont | ImgGrass0 | ImgGrass1 | ImgGrass2 | ImgMt02 | ImgMt11 | ImgMt12 | ImgMt13 | ImgMt22 | ImgNarioDie | ImgNarioLJump | ImgNarioLSlip | ImgNarioLStand | ImgNarioLWalk1 | ImgNarioLWalk2 | ImgNarioLWalk3 | ImgNarioRJump | ImgNarioRSlip | ImgNarioRStand | ImgNarioRWalk1 | ImgNarioRWalk2 | ImgNarioRWalk3 | ImgPole0 | ImgPole1 | ImgTitle       deriving (Eq) 
    4 imageTypes = [ImgBlock1, ImgBlock2, ImgBlock3, ImgBlock4, ImgBlock5, ImgCloud00, ImgCloud01, ImgCloud02, ImgCloud10, ImgCloud11, ImgCloud12, ImgDk00, ImgDk01, ImgDk10, ImgDk11, ImgFlag, ImgFont, ImgGrass0, ImgGrass1, ImgGrass2, ImgMt02, ImgMt11, ImgMt12, ImgMt13, ImgMt22, ImgNarioDie, ImgNarioLJump, ImgNarioLSlip, ImgNarioLStand, ImgNarioLWalk1, ImgNarioLWalk2, ImgNarioLWalk3, ImgNarioRJump, ImgNarioRSlip, ImgNarioRStand, ImgNarioRWalk1, ImgNarioRWalk2, ImgNarioRWalk3, ImgPole0, ImgPole1, ImgTitle] 
    5 imageFilenames = ["block1.bmp", "block2.bmp", "block3.bmp", "block4.bmp", "block5.bmp", "cloud00.bmp", "cloud01.bmp", "cloud02.bmp", "cloud10.bmp", "cloud11.bmp", "cloud12.bmp", "dk00.bmp", "dk01.bmp", "dk10.bmp", "dk11.bmp", "flag.bmp", "font.bmp", "grass0.bmp", "grass1.bmp", "grass2.bmp", "mt02.bmp", "mt11.bmp", "mt12.bmp", "mt13.bmp", "mt22.bmp", "narioDie.bmp", "narioLJump.bmp", "narioLSlip.bmp", "narioLStand.bmp", "narioLWalk1.bmp", "narioLWalk2.bmp", "narioLWalk3.bmp", "narioRJump.bmp", "narioRSlip.bmp", "narioRStand.bmp", "narioRWalk1.bmp", "narioRWalk2.bmp", "narioRWalk3.bmp", "pole0.bmp", "pole1.bmp", "title.bmp"] 
     3data ImageType = ImgBlock1 | ImgBlock2 | ImgBlock3 | ImgBlock4 | ImgBlock5 | ImgCloud00 | ImgCloud01 | ImgCloud02 | ImgCloud10 | ImgCloud11 | ImgCloud12 | ImgDk00 | ImgDk01 | ImgDk10 | ImgDk11 | ImgFlag | ImgFont | ImgGrass0 | ImgGrass1 | ImgGrass2 | ImgKuri0 | ImgKuri1 | ImgMt02 | ImgMt11 | ImgMt12 | ImgMt13 | ImgMt22 | ImgNarioDie | ImgNarioLJump | ImgNarioLSlip | ImgNarioLStand | ImgNarioLWalk1 | ImgNarioLWalk2 | ImgNarioLWalk3 | ImgNarioRJump | ImgNarioRSlip | ImgNarioRStand | ImgNarioRWalk1 | ImgNarioRWalk2 | ImgNarioRWalk3 | ImgPole0 | ImgPole1 | ImgTitle deriving (Eq) 
     4imageTypes = [ImgBlock1, ImgBlock2, ImgBlock3, ImgBlock4, ImgBlock5, ImgCloud00, ImgCloud01, ImgCloud02, ImgCloud10, ImgCloud11, ImgCloud12, ImgDk00, ImgDk01, ImgDk10, ImgDk11, ImgFlag, ImgFont, ImgGrass0, ImgGrass1, ImgGrass2, ImgKuri0, ImgKuri1, ImgMt02, ImgMt11, ImgMt12, ImgMt13, ImgMt22, ImgNarioDie, ImgNarioLJump, ImgNarioLSlip, ImgNarioLStand, ImgNarioLWalk1, ImgNarioLWalk2, ImgNarioLWalk3, ImgNarioRJump, ImgNarioRSlip, ImgNarioRStand, ImgNarioRWalk1, ImgNarioRWalk2, ImgNarioRWalk3, ImgPole0, ImgPole1, ImgTitle] 
     5imageFilenames = ["block1.bmp", "block2.bmp", "block3.bmp", "block4.bmp", "block5.bmp", "cloud00.bmp", "cloud01.bmp", "cloud02.bmp", "cloud10.bmp", "cloud11.bmp", "cloud12.bmp", "dk00.bmp", "dk01.bmp", "dk10.bmp", "dk11.bmp", "flag.bmp", "font.bmp", "grass0.bmp", "grass1.bmp", "grass2.bmp", "kuri0.bmp", "kuri1.bmp", "mt02.bmp", "mt11.bmp", "mt12.bmp", "mt13.bmp", "mt22.bmp", "narioDie.bmp", "narioLJump.bmp", "narioLSlip.bmp", "narioLStand.bmp", "narioLWalk1.bmp", "narioLWalk2.bmp", "narioLWalk3.bmp", "narioRJump.bmp", "narioRSlip.bmp", "narioRStand.bmp", "narioRWalk1.bmp", "narioRWalk2.bmp", "narioRWalk3.bmp", "pole0.bmp", "pole1.bmp", "title.bmp"] 
    66imageFn = fromJust . flip lookup (zip imageTypes imageFilenames) 
  • lang/haskell/nario/Main.hs

    r20641 r20661  
    2020import Event 
    2121import Actor 
     22import Actor.AnimBlock 
     23import Actor.Kuribo 
    2224 
    2325wndTitle = "NARIO in Haskell" 
     
    113115                        | otherwise                             = loop kss 
    114116 
     117 
     118 
     119-- マップのスクロールに応じたイベント 
     120scrollEvent :: Field -> Int -> (Field, [Event]) 
     121scrollEvent fld cx 
     122        | cx < length (head fld)        = foldl proc (fld, []) $ zip [0..] cols 
     123        | otherwise                                     = (fld, []) 
     124        where 
     125                proc (f, e) (cy, c) = 
     126                        case event cy c of 
     127                                Just ev -> (fieldSet f cx cy ' ', ev : e) 
     128                                Nothing -> (f, e) 
     129                cols = map (!! cx) fld 
     130                event cy c 
     131                        | c `elem` "k"  = Just $ EvAppearEnemy cx cy c 
     132                        | otherwise             = Nothing 
     133 
    115134-- ゲーム 
    116135doGame :: Field -> [[SDLKey]] -> [ImageResource -> Scr] 
     
    133152                        where 
    134153                                time' = max 0 (time gs - one `div` 25) 
    135                                 (pl', ev) = updatePlayer kp (fld gs) (pl gs) 
     154                                (fld', screv') = scrollEvent (fld gs) $ getScrollPos (pl gs) `div` chrSize + 18 
     155 
     156                                (pl', plev) = updatePlayer kp fld' (pl gs) 
    136157                                actors_updates = updateActors (actors gs) 
    137158                                actors' = filterActors $ map fst actors_updates 
    138159                                ev' = concatMap snd actors_updates 
    139160 
    140                                 gstmp = gs { pl = pl', actors = actors', time = time' } 
    141                                 gs' = procEvent gstmp (ev ++ ev') 
     161                                gstmp = gs { pl = pl', fld = fld', actors = actors', time = time' } 
     162                                gs' = procEvent gstmp (plev ++ ev' ++ screv') 
    142163 
    143164                initialState = GameGame { pl = newPlayer, fld = fldmap, actors = [], time = 400 * one } 
     
    148169-- イベントを処理 
    149170procEvent :: GameGame -> [Event] -> GameGame 
    150 procEvent gs ev = foldl f gs ev 
    151         where 
    152                 f gs (EvHitBlock imgtype cx cy) 
     171procEvent gs ev = foldl proc gs ev 
     172        where 
     173                proc gs (EvHitBlock imgtype cx cy) 
    153174                        | hardBlock c   = gs 
    154175                        | otherwise             = gs { fld = fld', actors = actors' } 
     
    157178                                actors' = actors gs ++ [ObjWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] 
    158179                                fld' = fieldSet (fld gs) cx cy '*' 
    159                 f gs (EvSetField cx cy c) = gs { fld = fld' } 
    160                         where 
    161                                 fld' = fieldSet (fld gs) cx cy c 
     180                proc gs (EvSetField cx cy c) = gs { fld = fieldSet (fld gs) cx cy c } 
     181                proc gs (EvAppearEnemy cx cy c) = gs { actors = actors gs ++ [ene] } 
     182                        where 
     183                                ene = case c of 
     184                                        'k'     -> ObjWrapper $ newKuribo cx cy 
    162185 
    163186 
     
    190213        puts 25 1 "TIME" 
    191214        puts 26 2 $ deciWide 3 ' ' ((time gs + one-1) `div` one) 
     215 
    192216        where 
    193217                puts = fontPut sur fontsur 
  • lang/haskell/nario/Makefile

    r20397 r20661  
    22PROJECT = nario 
    33 
    4 SRCS = $(wildcard *.hs) 
     4SRCS = $(wildcard *.hs) $(wildcard Actor/*.hs) 
     5OBJS = $(subst .hs,.o,$(SRCS)) $(subst .hs,.hi,$(SRCS)) 
    56 
    67all:    $(PROJECT).exe 
     
    1314 
    1415clean: 
    15         rm -f *.o 
    16         rm -f *.hi 
     16        rm -f $(OBJS) 
    1717        rm -f *.manifest 
    1818        rm -f *.exe 
  • lang/haskell/nario/README.txt

    r20641 r20661  
    33http://d.hatena.ne.jp/authorNari/20080422/1208880928 
    44 
    5 ��skell/HSDL �ō� 
     5を Haskell/HSDL で作る 
    66 
    77 
     
    1010 
    1111 
    12 ������  �J�[�\���L�[, ijkl 
    13                 �㉺���E 
     12★操作 
     13        カーソルキー, ijkl 
     14                上下左右 
    1415 
    15         �X�y�[�X�L�[, z 
    16                 A�{�^�� 
     16        スペースキー, z 
     17                Aボタン 
    1718 
    18         �V�t�g�L�[ 
    19                 B�{�^�� 
     19        シフトキー 
     20                Bボタン 
    2021 
    21         �G�X�P�[�v�L�[ 
    22                 �I�� 
     22        エスケープキー 
     23                終了 
    2324 
    2425 
    2526 
    26 ���t�@�C���\�� 
     27★ファイル構成 
    2728        data 
    28                 �f�[�^ 
     29                データ 
    2930        data/img 
    30                 �摜�f�[�^ 
     31                画像データ 
    3132 
    3233 
     
    3536 
    3637 
    37 ���Q�l 
     38★参考 
    3839        Super Nario GC 
    3940        http://d.hatena.ne.jp/authorNari/20080422/1208880928 
    4041 
    41         1-1 �}�b�v 
     42        1-1 マップ 
    4243        http://www.geocities.co.jp/SiliconValley-Sunnyvale/6160/newtech/m11.htm 
    4344 
    44         �t�H���g 
     45        フォント 
    4546        http://qtchicks.hp.infoseek.co.jp/fonts-nintendo.html 
    4647 
     
    4849        http://d.hatena.ne.jp/tanakh/20040803#p1 
    4950 
    50         ���݌^ 
     51        存在型 
    5152        http://d.hatena.ne.jp/syd_syd/20080805#p2 
  • lang/haskell/nario/data/stage0.map

    r20233 r20661  
    1  
     1                                                                                                                                                                                                                 
    22                                                                                                                                                                                                                 
    33                  123               1223                           123              1223                           123              1223                           123              1223              o 123      
     
    1111  _                                   []      l|  _      l|                                       _                                     XX  XX    _   XXX  XX                          XXXXXXX    _   !          
    1212 /,\             _          []        l|      l| /,\     l|      _                               /,\             _                     XXX  XXX  /,\ XXXX  XXX   _ []              [] XXXXXXXX   /,\  !   OO OO  
    13 /,.,\      78889/,\    789  l|        l| 7889 l|/,.,\    l|78889/,\    789                      /,.,\      78889/,\    789            XXXX  XXXX/,.,XXXXX  XXXX9/,\l|  789         l|XXXXXXXXX  /,.,\ X   OO OO9 
     13/,.,\      78889/,\ k  789  l|        l| 7889 l|/,.,\    l|78889/,\    789                      /,.,\      78889/,\    789            XXXX  XXXX/,.,XXXXX  XXXX9/,\l|  789         l|XXXXXXXXX  /,.,\ X   OO OO9 
    1414@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
    1515@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@