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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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