Changeset 20641

Show
Ignore:
Timestamp:
10/03/08 23:41:05 (3 months ago)
Author:
mokehehe
Message:

ブロックを叩いたときのアニメをマシにした

Location:
lang/haskell/nario
Files:
4 modified

Legend:

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

    r20534 r20641  
    1010import AppUtil 
    1111import Event 
     12import Field 
    1213 
    1314class Actor a where 
     
    1617        bDead :: a -> Bool 
    1718 
    18 -- ============================================================================ 
    19 -- ActNull 
    20 --      死亡 
    21  
    22 data AnimNull = AnimNull 
    23  
    24 instance Actor AnimNull where 
    25         update self = (self, []) 
    26         render self imgres scrx sur = return () 
    27         bDead self = True 
    28  
    2919 
    3020-- ============================================================================ 
     
    3222--      ブロックを叩いたときのバウンド演出 
    3323 
    34 data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 
     24data AnimBlock = AnimBlock { 
     25        startcy :: Int, 
     26        x :: Int, 
     27        y :: Int, 
     28        vy :: Int, 
     29        chr :: Cell 
     30        } 
    3531 
    3632instance Actor AnimBlock where 
    37         update self = result' 
     33        update self 
     34                | not (bDead self)      = (self', ev') 
     35                | otherwise                     = (self, []) 
     36 
    3837                where 
    39                         result' 
    40                                 | not bEnd      = (self { vy = vy', y = y' }, []) 
    41                                 | otherwise     = (self, [EvSetField (cellCrd $ x self) (startcy self) '@']) 
    42  
    4338                        vy' = vy self + gravity 
    4439                        y' = y self + vy' 
    45                         bEnd = y' >= startcy self * chrSize * one 
     40                        self' = self { vy = vy', y = y' } 
     41                        ev' = if (bDead self') 
     42                                then [EvSetField (cellCrd $ x self) (startcy self) $ chr self] 
     43                                else [] 
    4644 
    4745        render self imgres scrx sur = do 
    48                 blitSurface (getImageSurface imgres ImgBlock2) Nothing sur (pt ((x self) `div` one - scrx) ((y self) `div` one - 8)) 
     46                blitSurface (getImageSurface imgres $ chr2img $ chr self) Nothing sur (pt ((x self) `div` one - scrx) ((y self) `div` one - 8)) 
    4947                return () 
    5048 
    51         bDead self = False 
     49        bDead self = vy self > 0 && y self >= startcy self * chrSize * one 
    5250 
    53  
    54 newAnimBlock cx cy = AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one } 
    55  
     51newAnimBlock :: Int -> Int -> Cell -> AnimBlock 
     52newAnimBlock 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 
    5658 
    5759 
    5860-- ============================================================================ 
    5961 
    60 {- 
    61 updateActor :: Actor -> (Actor, [Event]) 
    62 updateActor ActNull                             = updateNull 
    63 updateActor (ActAnimBlock a)    = updateAnimBlock a 
     62---- 
     63data ObjWrapper = forall a. Actor a => ObjWrapper a     -- ݌^a͈̓͂잃NXDuckɐ 
    6464 
    65 renderActor :: Actor -> ImageResource -> Int -> Surface -> IO () 
    66 renderActor ActNull                             = renderNull 
    67 renderActor (ActAnimBlock a)    = renderAnimBlock a 
     65updateActors :: [ObjWrapper] -> [(ObjWrapper, [Event])] 
     66updateActors = map (\(ObjWrapper x) -> let (x', ev') = update x in (ObjWrapper x', ev')) 
    6867 
    69 bDieActor :: Actor -> Bool 
    70 bDieActor ActNull                               = bDieNull 
    71 bDieActor (ActAnimBlock a)              = bDieAnimBlock a 
    72 -} 
     68filterActors :: [ObjWrapper] -> [ObjWrapper] 
     69filterActors = filter (\(ObjWrapper x) -> not $ bDead x) 
     70 
     71renderActors :: ImageResource -> Int -> Surface -> [ObjWrapper] -> IO () 
     72renderActors imgres ofsx sur = mapM_ (\(ObjWrapper x) -> render x imgres ofsx sur) 
  • lang/haskell/nario/Field.hs

    r20397 r20641  
    1313        fieldSet, 
    1414        isBlock, 
    15         renderField 
     15        renderField, 
     16        chr2img, 
     17        hardBlock 
    1618) where 
    1719 
     
    4042chr2img 'X' = ImgBlock3 
    4143chr2img '?' = ImgBlock4 
     44chr2img '#' = ImgBlock5 
    4245chr2img '_' = ImgMt02 
    4346chr2img '/' = ImgMt11 
     
    6467 
    6568isBlock :: Cell -> Bool 
    66 isBlock c = c `elem` "@OX?[]l|*" 
     69isBlock = (`elem` "@OX?#[]l|*") 
     70 
     71hardBlock :: Cell -> Bool 
     72hardBlock = (`elem` "#X@*") 
    6773 
    6874inField :: Field -> Int -> Int -> Bool 
  • lang/haskell/nario/Main.hs

    r20534 r20641  
    7575                _               -> checkSDLEvent 
    7676 
    77 ---- 
    78 data ObjWrapper = forall a. Actor a => ObjWrapper a     -- 存在型aの動く範囲を型クラスDuckに制限 
    79  
    80 updateActors :: [ObjWrapper] -> [(ObjWrapper, [Event])] 
    81 updateActors = map (\(ObjWrapper x) -> let (x', ev') = update x in (ObjWrapper x', ev')) 
    82  
    83 renderActors :: ImageResource -> Int -> Surface -> [ObjWrapper] -> IO () 
    84 renderActors imgres ofsx sur = mapM_ (\(ObjWrapper x) -> render x imgres ofsx sur) 
    85  
    8677 
    8778-- 状態 
     
    144135                                (pl', ev) = updatePlayer kp (fld gs) (pl gs) 
    145136                                actors_updates = updateActors (actors gs) 
    146                                 actors' = map fst actors_updates 
     137                                actors' = filterActors $ map fst actors_updates 
    147138                                ev' = concatMap snd actors_updates 
    148139 
     
    159150procEvent gs ev = foldl f gs ev 
    160151        where 
    161                 f gs (EvHitBlock imgtype cx cy) = gs { fld = fld', actors = actors' } 
    162                         where 
     152                f gs (EvHitBlock imgtype cx cy) 
     153                        | hardBlock c   = gs 
     154                        | otherwise             = gs { fld = fld', actors = actors' } 
     155                        where 
     156                                c = fieldRef (fld gs) cx cy 
     157                                actors' = actors gs ++ [ObjWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] 
    163158                                fld' = fieldSet (fld gs) cx cy '*' 
    164                                 actors' = (ObjWrapper $ newAnimBlock cx cy) : actors gs 
    165159                f gs (EvSetField cx cy c) = gs { fld = fld' } 
    166160                        where 
     
    189183renderInfo :: GameGame -> ImageResource -> Scr 
    190184renderInfo gs imgres sur = do 
    191         puts 3 1 "MARIO" 
     185        puts 3 1 "NARIO" 
    192186        puts 3 2 $ deciWide 6 '0' $ getPlayerScore (pl gs) 
    193187        puts 11 2 ("?*" ++ deciWide 2 '0' (getPlayerMedal (pl gs))) 
  • lang/haskell/nario/README.txt

    r20175 r20641  
    4444        �t�H���g 
    4545        http://qtchicks.hp.infoseek.co.jp/fonts-nintendo.html 
     46 
     47        unsafeInterleaveIO 
     48        http://d.hatena.ne.jp/tanakh/20040803#p1 
     49 
     50        ���݌^ 
     51        http://d.hatena.ne.jp/syd_syd/20080805#p2