Changeset 20534
- Timestamp:
- 10/03/08 01:04:54 (3 months ago)
- Location:
- lang/haskell/nario
- Files:
-
- 4 modified
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 -} -
lang/haskell/nario/Images.hs
r20397 r20534 1 1 module Images (ImageType(..), imageTypes, imageFn) where 2 import Maybe 2 import Maybe (fromJust) 3 3 data ImageType = ImgBlock1 | ImgBlock2 | ImgBlock3 | ImgBlock4 | ImgBlock5 | ImgCloud00 | ImgCloud01 | ImgCloud02 | ImgCloud10 | ImgCloud11 | ImgCloud12 | ImgDk00 | ImgDk01 | ImgDk10 | ImgDk11 | ImgFlag | ImgFont | ImgGrass0 | ImgGrass1 | ImgGrass2 | ImgMt02 | ImgMt11 | ImgMt12 | ImgMt13 | ImgMt22 | ImgNarioDie | ImgNarioLJump | ImgNarioLSlip | ImgNarioLStand | ImgNarioLWalk1 | ImgNarioLWalk2 | ImgNarioLWalk3 | ImgNarioRJump | ImgNarioRSlip | ImgNarioRStand | ImgNarioRWalk1 | ImgNarioRWalk2 | ImgNarioRWalk3 | ImgPole0 | ImgPole1 | ImgTitle deriving (Eq) 4 4 imageTypes = [ImgBlock1, ImgBlock2, ImgBlock3, ImgBlock4, ImgBlock5, ImgCloud00, ImgCloud01, ImgCloud02, ImgCloud10, ImgCloud11, ImgCloud12, ImgDk00, ImgDk01, ImgDk10, ImgDk11, ImgFlag, ImgFont, ImgGrass0, ImgGrass1, ImgGrass2, ImgMt02, ImgMt11, ImgMt12, ImgMt13, ImgMt22, ImgNarioDie, ImgNarioLJump, ImgNarioLSlip, ImgNarioLStand, ImgNarioLWalk1, ImgNarioLWalk2, ImgNarioLWalk3, ImgNarioRJump, ImgNarioRSlip, ImgNarioRStand, ImgNarioRWalk1, ImgNarioRWalk2, ImgNarioRWalk3, ImgPole0, ImgPole1, ImgTitle] -
lang/haskell/nario/Main.hs
r20453 r20534 1 {-# OPTIONS_GHC -fglasgow-exts #-} 2 1 3 -- Nario 2 4 … … 74 76 75 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) 76 85 77 86 … … 81 90 pl :: Player, 82 91 fld :: Field, 83 actors :: [ Actor],92 actors :: [ObjWrapper], 84 93 time :: Int 85 94 } … … 134 143 time' = max 0 (time gs - one `div` 25) 135 144 (pl', ev) = updatePlayer kp (fld gs) (pl gs) 136 actors_updates = map updateActor(actors gs)145 actors_updates = updateActors (actors gs) 137 146 actors' = map fst actors_updates 138 147 ev' = concatMap snd actors_updates … … 153 162 where 154 163 fld' = fieldSet (fld gs) cx cy '*' 155 actors' = ( newAnimBlock cx cy) : actors gs164 actors' = (ObjWrapper $ newAnimBlock cx cy) : actors gs 156 165 f gs (EvSetField cx cy c) = gs { fld = fld' } 157 166 where … … 170 179 renderPlayer sur imgres scrx (pl gs) 171 180 172 mapM_ (\act -> renderActor act imgres scrx sur)(actors gs)181 renderActors imgres scrx sur (actors gs) 173 182 return () 174 183 -
lang/haskell/nario/tool/listup-imgs.hs
r20453 r20534 43 43 44 44 putStrLn "module Images (ImageType(..), imageTypes, imageFn) where" 45 putStrLn "import Maybe "45 putStrLn "import Maybe (fromJust)" 46 46 47 47 putStrLn $ "data ImageType = " ++ intercalate " | " symbols ++ "\tderiving (Eq)"
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)