Changeset 20641 for lang/haskell/nario/Actor.hs
- Timestamp:
- 10/03/08 23:41:05 (3 months ago)
- Files:
-
- 1 modified
-
lang/haskell/nario/Actor.hs (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Actor.hs
r20534 r20641 10 10 import AppUtil 11 11 import Event 12 import Field 12 13 13 14 class Actor a where … … 16 17 bDead :: a -> Bool 17 18 18 -- ============================================================================19 -- ActNull20 -- 死亡21 22 data AnimNull = AnimNull23 24 instance Actor AnimNull where25 update self = (self, [])26 render self imgres scrx sur = return ()27 bDead self = True28 29 19 30 20 -- ============================================================================ … … 32 22 -- ブロックを叩いたときのバウンド演出 33 23 34 data AnimBlock = AnimBlock { startcy :: Int, x :: Int, y :: Int, vy :: Int } 24 data AnimBlock = AnimBlock { 25 startcy :: Int, 26 x :: Int, 27 y :: Int, 28 vy :: Int, 29 chr :: Cell 30 } 35 31 36 32 instance Actor AnimBlock where 37 update self = result' 33 update self 34 | not (bDead self) = (self', ev') 35 | otherwise = (self, []) 36 38 37 where 39 result'40 | not bEnd = (self { vy = vy', y = y' }, [])41 | otherwise = (self, [EvSetField (cellCrd $ x self) (startcy self) '@'])42 43 38 vy' = vy self + gravity 44 39 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 [] 46 44 47 45 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)) 49 47 return () 50 48 51 bDead self = False49 bDead self = vy self > 0 && y self >= startcy self * chrSize * one 52 50 53 54 newAnimBlock cx cy = AnimBlock { startcy = cy, x = cx * chrSize * one, y = cy * chrSize * one, vy = -3 * one } 55 51 newAnimBlock :: Int -> Int -> Cell -> AnimBlock 52 newAnimBlock 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 56 58 57 59 58 60 -- ============================================================================ 59 61 60 {- 61 updateActor :: Actor -> (Actor, [Event]) 62 updateActor ActNull = updateNull 63 updateActor (ActAnimBlock a) = updateAnimBlock a 62 ---- 63 data ObjWrapper = forall a. Actor a => ObjWrapper a -- ^a͈̓͂잃NXDuckɐ 64 64 65 renderActor :: Actor -> ImageResource -> Int -> Surface -> IO () 66 renderActor ActNull = renderNull 67 renderActor (ActAnimBlock a) = renderAnimBlock a 65 updateActors :: [ObjWrapper] -> [(ObjWrapper, [Event])] 66 updateActors = map (\(ObjWrapper x) -> let (x', ev') = update x in (ObjWrapper x', ev')) 68 67 69 bDieActor :: Actor -> Bool 70 bDieActor ActNull = bDieNull 71 bDieActor (ActAnimBlock a) = bDieAnimBlock a 72 -} 68 filterActors :: [ObjWrapper] -> [ObjWrapper] 69 filterActors = filter (\(ObjWrapper x) -> not $ bDead x) 70 71 renderActors :: ImageResource -> Int -> Surface -> [ObjWrapper] -> IO () 72 renderActors imgres ofsx sur = mapM_ (\(ObjWrapper x) -> render x imgres ofsx sur)
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)