Changeset 19996
- Timestamp:
- 09/27/08 07:28:08 (5 years ago)
- Location:
- lang/haskell/nario
- Files:
-
- 4 added
- 3 moved
-
Const.hs (added)
-
Main.lhs (moved) (moved from lang/haskell/nario/main.hs) (5 diffs)
-
Player.hs (added)
-
README.txt (added)
-
Sound.hs (added)
-
Util.lhs (moved) (moved from lang/haskell/nario/util.hs) (4 diffs)
-
sdlutil.lhs (moved) (moved from lang/haskell/nario/sdlutil.hs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Main.lhs
r19989 r19996 11 11 import SDLUtil 12 12 import Util 13 import Player 13 14 14 15 ----------------------------------- … … 20 21 wndSize = sz 256 240 21 22 22 23 -- �摜 24 data ImageType = 25 ImgNario00 | ImgNario01 | ImgNario02 | ImgNario03 | ImgNario04 26 | ImgNario10 | ImgNario11 | ImgNario12 | ImgNario13 | ImgNario14 27 | ImgBlock1 | ImgBlock2 | ImgBlock3 | ImgBlock4 | ImgBlock5 28 deriving Eq 29 30 imageFn ImgNario00 = "nario00.bmp" 31 imageFn ImgNario01 = "nario01.bmp" 32 imageFn ImgNario02 = "nario02.bmp" 33 imageFn ImgNario03 = "nario03.bmp" 34 imageFn ImgNario04 = "nario04.bmp" 35 imageFn ImgNario10 = "nario10.bmp" 36 imageFn ImgNario11 = "nario11.bmp" 37 imageFn ImgNario12 = "nario12.bmp" 38 imageFn ImgNario13 = "nario13.bmp" 39 imageFn ImgNario14 = "nario14.bmp" 40 imageFn ImgBlock1 = "block1.bmp" 41 imageFn ImgBlock2 = "block2.bmp" 42 imageFn ImgBlock3 = "block3.bmp" 43 imageFn ImgBlock4 = "block4.bmp" 44 imageFn ImgBlock5 = "block5.bmp" 45 46 images = [ 47 ImgNario00, ImgNario01, ImgNario02, ImgNario03, ImgNario04, 48 ImgNario10, ImgNario11, ImgNario12, ImgNario13, ImgNario14, 49 ImgBlock1, ImgBlock2, ImgBlock3, ImgBlock4, ImgBlock5 50 ] 23 -- �w�i�F 24 backColor = 0x2891ff -- �� 51 25 52 26 53 27 54 type ImageResource = [(ImageType, Surface)]55 28 56 29 57 30 31 -- �}�b�v 58 32 59 33 fieldMap = [ … … 92 66 93 67 94 data Player = Player {95 x :: Int,96 y :: Int,97 lr :: Int98 }99 68 100 one = 256101 102 newPlayer = Player {103 x = 1 * 16 * one,104 y = 12 * 16 * one,105 lr = 1106 }107 108 updatePlayer :: Player -> KeyProc -> Player109 updatePlayer player kp =110 player { x = x', y = y', lr = lr' }111 where112 x'113 | isPressed (kp GKLeft) = (x player) - 1 * one114 | isPressed (kp GKRight) = (x player) + 1 * one115 | otherwise = x player116 y'117 | isPressed (kp GKUp) = (y player) - 1 * one118 | isPressed (kp GKDown) = (y player) + 1 * one119 | otherwise = y player120 lr'121 | isPressed (kp GKLeft) = 0122 | isPressed (kp GKRight) = 1123 | otherwise = lr player124 125 renderPlayer sur player imgres =126 blitSurface (getImageSurface imgres chr) Nothing sur pos127 where128 pos = pt ((x player) `div` one) ((y player) `div` one)129 chr = if (lr player) == 0130 then ImgNario00131 else ImgNario10132 133 134 -- �摜���\�[�X�ǂݍ���135 loadImageResource :: IO ImageResource136 loadImageResource = mapM load images137 where138 load imgtype = do139 sur <- loadBMP $ ("img/" ++) $ imageFn imgtype140 -- colorKey <- mapRGB (surfacePixelFormat sur) $ Color r g b a141 setColorKey sur [SRCCOLORKEY] 0142 return (imgtype, sur)143 r = 0144 g = 0145 b = 0146 a = 255147 148 149 getImageSurface :: ImageResource -> ImageType -> Surface150 getImageSurface imgres t = fromJust $ lookup t imgres151 69 152 70 -- ���C�����[�v … … 171 89 172 90 checkEvent = do 173 ev <- pollEvent174 case ev of175 Just QuitEvent -> return True176 Just (KeyboardEvent { kbPress = True, kbKeysym = Keysym { ksSym = ks, ksMod = km } })177 | ks == SDLK_ESCAPE -> return True178 | ks == SDLK_F4 && (KMOD_LALT `elem` km ||179 KMOD_RALT `elem` km) -> return True180 Nothing -> return False181 _ -> checkEvent91 ev <- pollEvent 92 case ev of 93 Just QuitEvent -> return True 94 Just (KeyboardEvent { kbPress = True, kbKeysym = Keysym { ksSym = ks, ksMod = km } }) 95 | ks == SDLK_ESCAPE -> return True 96 | ks == SDLK_F4 && (KMOD_LALT `elem` km || 97 KMOD_RALT `elem` km) -> return True 98 Nothing -> return False 99 _ -> checkEvent 182 100 183 101 … … 209 127 210 128 211 {-212 wav <- loadWAV "snd/jump.wav"213 214 playAudioData ad = do215 case audioSpec ad of216 Just spec -> do217 let freq = asFreq spec218 let format = asFormat spec219 let channel = asChannels spec220 let samples = asSamples spec221 print (unlines [show freq, show format, show channel, show samples])222 openAudio freq format channel samples cb223 return ()224 Nothing -> do225 print "audioSpec error"226 return ()227 where228 cb x = return [ad]229 -}230 231 232 backColor = 0x2891ff233 234 235 129 -- �`�揈�� 236 130 onDraw :: Surface -> ImageResource -> GameState -> IO () -
lang/haskell/nario/Util.lhs
r19989 r19996 6 6 import Multimedia.SDL 7 7 8 import Const 9 8 10 -- �L�[�{�[�h���� 9 11 10 data GameKey=11 GKUp | GKDown | GKLeft | GKRight | GKRotate12 deriving (Eq, Show,Enum)12 data PadBtn = 13 PadU | PadD | PadL | PadR | PadA | PadB 14 deriving (Eq, Show, Enum) 13 15 14 16 data KeyState = 15 17 Pushed | Pushing | Released | Releasing 16 deriving (Eq, Show)18 deriving (Eq, Show) 17 19 18 20 isPressed Pushed = True … … 20 22 isPressed _ = False 21 23 22 type KeyProc = GameKey-> KeyState24 type KeyProc = PadBtn -> KeyState 23 25 24 26 keyProc bef cur gk … … 28 30 | bp && cp = Pushing 29 31 where 30 bp = (mapPhyKey gk) `elem` bef 31 cp = (mapPhyKey gk) `elem` cur 32 bp = any (flip elem bef) phykeys 33 cp = any (flip elem cur) phykeys 34 phykeys = mapPhyKey gk 32 35 33 mapPhyKey GKUp = SDLK_UP 34 mapPhyKey GKDown = SDLK_DOWN 35 mapPhyKey GKLeft = SDLK_LEFT 36 mapPhyKey GKRight = SDLK_RIGHT 37 mapPhyKey GKRotate = SDLK_z 36 mapPhyKey PadU = [SDLK_UP, SDLK_i] 37 mapPhyKey PadD = [SDLK_DOWN, SDLK_k] 38 mapPhyKey PadL = [SDLK_LEFT, SDLK_j] 39 mapPhyKey PadR = [SDLK_RIGHT, SDLK_l] 40 mapPhyKey PadA = [SDLK_SPACE] 41 mapPhyKey PadB = [SDLK_LSHIFT, SDLK_RSHIFT] 38 42 39 43 -- ���Ԓ��� … … 62 66 toPsec dt = toInteger (tdMin dt * 60 + tdSec dt) * picosec + tdPicosec dt 63 67 picosec = 1000000000000 68 69 70 71 -- �摜���\�[�X 72 type ImageResource = [(ImageType, Surface)] 73 74 75 -- �摜���\�[�X�ǂݍ��� 76 loadImageResource :: IO ImageResource 77 loadImageResource = mapM load images 78 where 79 load imgtype = do 80 sur <- loadBMP $ ("img/" ++) $ imageFn imgtype 81 -- colorKey <- mapRGB (surfacePixelFormat sur) $ Color r g b a 82 setColorKey sur [SRCCOLORKEY] 0 83 return (imgtype, sur) 84 r = 0 85 g = 0 86 b = 0 87 a = 255 88 89 90 getImageSurface :: ImageResource -> ImageType -> Surface 91 getImageSurface imgres t = fromJust $ lookup t imgres
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)