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

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

Files:
1 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)