Changeset 20534 for lang/haskell/nario/Actor.hs
- Timestamp:
- 10/03/08 01:04:54 (3 months ago)
- Files:
-
- 1 modified
-
lang/haskell/nario/Actor.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Actor.hs
r20397 r20534 1 {-# OPTIONS_GHC -fglasgow-exts #-} 1 2 2 3 module Actor where … … 10 11 import Event 11 12 12 13 data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 14 15 data Actor = ActNull | ActAnimBlock AnimBlock 13 class Actor a where 14 update :: a -> (a, [Event]) 15 render :: a -> ImageResource -> Int -> Surface -> IO () 16 bDead :: a -> Bool 16 17 17 18 -- ============================================================================ … … 19 20 -- 死亡 20 21 21 updateNull = (ActNull, []) 22 data AnimNull = AnimNull 22 23 23 renderNull imgres scrx sur = return () 24 25 bDieNull = True 24 instance Actor AnimNull where 25 update self = (self, []) 26 render self imgres scrx sur = return () 27 bDead self = True 26 28 27 29 … … 30 32 -- ブロックを叩いたときのバウンド演出 31 33 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) '@']) 34 data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 37 35 38 vy' = vy self + gravity 39 y' = y self + vy' 40 bEnd = y' >= startcy self * chrSize * one 36 instance 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 41 52 42 53 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 54 newAnimBlock cx cy = AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one } 51 55 52 56 … … 54 58 -- ============================================================================ 55 59 60 {- 56 61 updateActor :: Actor -> (Actor, [Event]) 57 62 updateActor ActNull = updateNull … … 65 70 bDieActor ActNull = bDieNull 66 71 bDieActor (ActAnimBlock a) = bDieAnimBlock a 67 72 -}
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)