Changeset 20673 for lang/haskell
- Timestamp:
- 10/04/08 14:32:30 (2 months ago)
- Location:
- lang/haskell/nario
- Files:
-
- 5 modified
-
Actor.hs (modified) (3 diffs)
-
Actor/Kinoko.hs (modified) (2 diffs)
-
AppUtil.hs (modified) (2 diffs)
-
Main.hs (modified) (5 diffs)
-
Player.hs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Actor.hs
r20670 r20673 3 3 module Actor ( 4 4 Actor(..), 5 ObjWrapper(..),5 ActorWrapper(..), 6 6 updateActors, 7 7 filterActors, … … 11 11 import Multimedia.SDL (Surface) 12 12 13 import Event 14 import AppUtil 15 import Field 13 import Event (Event) 14 import AppUtil (ImageResource, Rect) 15 import Field (Field) 16 16 17 17 … … 19 19 update :: Field -> a -> (a, [Event]) 20 20 render :: a -> ImageResource -> Int -> Surface -> IO () 21 21 22 bDead :: a -> Bool 22 23 bDead _ = False 24 25 getHitRect :: a -> Maybe Rect 26 getHitRect _ = Nothing 23 27 24 28 -- ============================================================================ 25 29 26 30 ---- 27 data ObjWrapper = forall a. Actor a => ObjWrapper a -- 存在型aの動く範囲を型クラスに制限31 data ActorWrapper = forall a. Actor a => ActorWrapper a -- 存在型aの動く範囲を型クラスに制限 28 32 29 updateActors :: Field -> [ ObjWrapper] -> [(ObjWrapper, [Event])]30 updateActors fld = map (\( ObjWrapper x) -> let (x', ev') = update fld x in (ObjWrapper x', ev'))33 updateActors :: Field -> [ActorWrapper] -> [(ActorWrapper, [Event])] 34 updateActors fld = map (\(ActorWrapper x) -> let (x', ev') = update fld x in (ActorWrapper x', ev')) 31 35 32 filterActors :: [ ObjWrapper] -> [ObjWrapper]33 filterActors = filter (\( ObjWrapper x) -> not $ bDead x)36 filterActors :: [ActorWrapper] -> [ActorWrapper] 37 filterActors = filter (\(ActorWrapper x) -> not $ bDead x) 34 38 35 renderActors :: ImageResource -> Int -> Surface -> [ ObjWrapper] -> IO ()36 renderActors imgres ofsx sur = mapM_ (\( ObjWrapper x) -> render x imgres ofsx sur)39 renderActors :: ImageResource -> Int -> Surface -> [ActorWrapper] -> IO () 40 renderActors imgres ofsx sur = mapM_ (\(ActorWrapper x) -> render x imgres ofsx sur) -
lang/haskell/nario/Actor/Kinoko.hs
r20670 r20673 5 5 ) where 6 6 7 import Multimedia.SDL hiding (Event)7 import Multimedia.SDL (blitSurface, pt) 8 8 9 9 import Actor (Actor(..)) 10 10 import Const 11 11 import Util (sgn) 12 import AppUtil 12 import AppUtil (getImageSurface, cellCrd, Rect(..)) 13 13 import Images 14 14 import Field … … 47 47 bDead self = y self `div` one >= screenHeight + chrSize * 3 48 48 49 getHitRect self = Just $ Rect (xx - 8) (yy - 16) (xx + 8) yy 50 where 51 xx = x self `div` one 52 yy = y self `div` one 53 49 54 50 55 newKinoko :: Int -> Int -> Kinoko -
lang/haskell/nario/AppUtil.hs
r20397 r20673 1 1 module AppUtil where 2 2 3 import Multimedia.SDL 3 import Multimedia.SDL (Surface, SDLKey(..), loadBMP, freeSurface, surfacePixelFormat, displayFormat, pfPalette, setColorKey, SurfaceFlag(..)) 4 4 import Data.Maybe (fromJust) 5 5 … … 73 73 cellCrd :: Int -> Int 74 74 cellCrd x = x `div` (chrSize * one) 75 76 77 78 -- ======== 79 data Rect = Rect Int Int Int Int 80 81 82 ishit :: Rect -> Rect -> Bool 83 ishit (Rect l1 t1 r1 b1) (Rect l2 t2 r2 b2) = 84 l1 < r2 && t1 < b2 && l2 < r1 && t2 < b1 -
lang/haskell/nario/Main.hs
r20670 r20673 76 76 pl :: Player, 77 77 fld :: Field, 78 actors :: [ ObjWrapper],78 actors :: [ActorWrapper], 79 79 time :: Int 80 80 } … … 125 125 | otherwise = Nothing 126 126 127 128 129 -- 当たり判定 130 hitcheck :: Player -> [ActorWrapper] -> (Player, [ActorWrapper]) 131 hitcheck player actors = foldl proc (player, []) actors 132 where 133 proc (pl, ac) (ActorWrapper a) = case getHitRect a of 134 Nothing -> nothingHappened 135 Just rc -> 136 if not $ ishit plrc rc 137 then nothingHappened 138 else (pl', ac') 139 where 140 nothingHappened = (pl, ac ++ [ActorWrapper a]) 141 plrc = getPlayerHitRect player 142 pl' = pl 143 ac' = ac 144 145 127 146 -- ゲーム 128 147 doGame :: Field -> [[SDLKey]] -> [ImageResource -> Scr] … … 152 171 ev' = concatMap snd actors_updates 153 172 154 gstmp = gs { pl = pl', fld = fld', actors = actors', time = time' } 173 (pl'', actors'') = hitcheck pl' actors' 174 175 gstmp = gs { pl = pl'', fld = fld', actors = actors'', time = time' } 155 176 gs' = procEvent gstmp (plev ++ ev' ++ screv') 156 177 157 178 initialState = GameGame { pl = newPlayer, fld = fldmap, actors = [], time = 400 * one } 158 179 180 -- ゲームオーバー 159 181 doGameOver fldmap kss = doTitle fldmap kss 160 182 … … 170 192 c = fieldRef (fld gs) cx cy 171 193 items 172 | c == 'K' = [ ObjWrapper $ newKinoko cx cy]194 | c == 'K' = [ActorWrapper $ newKinoko cx cy] 173 195 | otherwise = [] 174 actors' = actors gs ++ [ ObjWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] ++ items196 actors' = actors gs ++ [ActorWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] ++ items 175 197 fld' = fieldSet (fld gs) cx cy '*' 176 198 proc gs (EvSetField cx cy c) = gs { fld = fieldSet (fld gs) cx cy c } … … 178 200 where 179 201 ene = case c of 180 'k' -> ObjWrapper $ newKuribo cx cy181 'n' -> ObjWrapper $ newNokonoko cx cy202 'k' -> ActorWrapper $ newKuribo cx cy 203 'n' -> ActorWrapper $ newNokonoko cx cy 182 204 183 205 -
lang/haskell/nario/Player.hs
r20670 r20673 8 8 getScrollPos, 9 9 getPlayerYPos, 10 getPlayerHitRect, 10 11 getPlayerMedal, 11 12 getPlayerScore 12 13 ) where 13 14 14 import Multimedia.SDL hiding (Event)15 import Multimedia.SDL (blitSurface, pt) 15 16 16 17 import Util 17 import AppUtil 18 import AppUtil (KeyProc, isPressed, PadBtn(..), cellCrd, KeyState(..), getImageSurface, Rect(..)) 18 19 import Const 19 20 import Images … … 200 201 getPlayerYPos = (`div` one) . y 201 202 203 -- 当たり判定用矩形 204 getPlayerHitRect :: Player -> Rect 205 getPlayerHitRect self = Rect (xx - 6) (yy - 16) (xx + 6) yy 206 where 207 xx = x self `div` one 208 yy = y self `div` one 209 202 210 -- メダル枚数取得 203 211 getPlayerMedal :: Player -> Int
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)