Show
Ignore:
Timestamp:
10/03/08 01:04:54 (3 months ago)
Author:
mokehehe
Message:

Existence 型を使って書き換え

Files:
1 modified

Legend:

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

    r20397 r20534  
     1{-# OPTIONS_GHC -fglasgow-exts #-} 
    12 
    23module Actor where 
     
    1011import Event 
    1112 
    12  
    13 data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 
    14  
    15 data Actor = ActNull | ActAnimBlock AnimBlock 
     13class Actor a where 
     14        update :: a -> (a, [Event]) 
     15        render :: a -> ImageResource -> Int -> Surface -> IO () 
     16        bDead :: a -> Bool 
    1617 
    1718-- ============================================================================ 
     
    1920--      死亡 
    2021 
    21 updateNull = (ActNull, []) 
     22data AnimNull = AnimNull 
    2223 
    23 renderNull imgres scrx sur = return () 
    24  
    25 bDieNull = True 
     24instance Actor AnimNull where 
     25        update self = (self, []) 
     26        render self imgres scrx sur = return () 
     27        bDead self = True 
    2628 
    2729 
     
    3032--      ブロックを叩いたときのバウンド演出 
    3133 
    32 updateAnimBlock self = result' 
    33         where 
    34                 result' 
    35                         | not bEnd      = (ActAnimBlock $ self { vy = vy', y = y' }, []) 
    36                         | otherwise     = (ActNull, [EvSetField (cellCrd $ x self) (startcy self) '@']) 
     34data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 
    3735 
    38                 vy' = vy self + gravity 
    39                 y' = y self + vy' 
    40                 bEnd = y' >= startcy self * chrSize * one 
     36instance Actor AnimBlock where 
     37        update self = result' 
     38                where 
     39                        result' 
     40                                | not bEnd      = (self { vy = vy', y = y' }, []) 
     41                                | otherwise     = (self, [EvSetField (cellCrd $ x self) (startcy self) '@']) 
     42 
     43                        vy' = vy self + gravity 
     44                        y' = y self + vy' 
     45                        bEnd = y' >= startcy self * chrSize * one 
     46 
     47        render self imgres scrx sur = do 
     48                blitSurface (getImageSurface imgres ImgBlock2) Nothing sur (pt ((x self) `div` one - scrx) ((y self) `div` one - 8)) 
     49                return () 
     50 
     51        bDead self = False 
    4152 
    4253 
    43 renderAnimBlock self imgres scrx sur = do 
    44         blitSurface (getImageSurface imgres ImgBlock2) Nothing sur (pt ((x self) `div` one - scrx) ((y self) `div` one - 8)) 
    45         return () 
    46  
    47 bDieAnimBlock self = False 
    48  
    49 newAnimBlock cx cy = ActAnimBlock $ AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one } 
    50  
     54newAnimBlock cx cy = AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one } 
    5155 
    5256 
     
    5458-- ============================================================================ 
    5559 
     60{- 
    5661updateActor :: Actor -> (Actor, [Event]) 
    5762updateActor ActNull                             = updateNull 
     
    6570bDieActor ActNull                               = bDieNull 
    6671bDieActor (ActAnimBlock a)              = bDieAnimBlock a 
    67  
     72-}