Changeset 20943 for lang/haskell

Show
Ignore:
Timestamp:
10/08/08 07:34:08 (2 months ago)
Author:
mokehehe
Message:

キー入力処理変更
Sキーでスクリーンショットを取れるように

Location:
lang/haskell/nario
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Actor/AnimBlock.hs

    r20925 r20943  
    3636                                else [] 
    3737 
    38         render self imgres scrx sur = do 
     38        render self imgres scrx sur = 
    3939                putimg sur imgres (chr2img $ chr self) (x self `div` one - scrx) (y self `div` one - 8) 
    40                 return () 
    4140 
    4241        bDead self = vy self > 0 && y self >= startcy self * chrSize * one 
  • lang/haskell/nario/Actor/BrokenBlock.hs

    r20925 r20943  
    2424        update _ self = (self { x = x self + vx self, y = y self + vy self, vy = vy self + gravity }, []) 
    2525 
    26         render self imgres scrx sur = do 
     26        render self imgres scrx sur = 
    2727                putimg sur imgres ImgBroken (x self `div` one - 4 - scrx) (y self `div` one - 4 - 8) 
    28                 return () 
    2928 
    3029        bDead self = y self >= (screenHeight + chrSize * 2) * one 
  • lang/haskell/nario/Actor/CoinGet.hs

    r20925 r20943  
    3232                        self' = self { y = y self + vy self, vy = vy self + gravity, cnt = cnt self + 1 } 
    3333 
    34         render self imgres scrx sur = do 
     34        render self imgres scrx sur = 
    3535                putimg sur imgres imgtype (sx self - scrx) (y self `div` one - 8) 
    36                 return () 
    3736                where 
    3837                        imgtype = imgtbl !! (cnt self `div` 2 `mod` 4) 
  • lang/haskell/nario/Actor/Flower.hs

    r20925 r20943  
    2727        update fld self = (self, []) 
    2828 
    29         render self imgres scrx sur = do 
     29        render self imgres scrx sur = 
    3030                putimg sur imgres ImgFlower ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - 15 - 8) 
    31                 return () 
    3231 
    3332        getHitRect self = Just $ Rect (xx - 8) (yy - 16) (xx + 8) yy 
  • lang/haskell/nario/Actor/Kinoko.hs

    r20925 r20943  
    3232                        (x', y', vx', vy') = updateActorBase fld (x self, y self, vx self, vy self) 
    3333 
    34         render self imgres scrx sur = do 
    35                 putimg sur imgres imgtype ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    36                 return () 
    37                 where 
    38                         imgtype = ImgKinoko 
     34        render self imgres scrx sur = 
     35                putimg sur imgres ImgKinoko ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    3936 
    4037        bDead self = y self >= (screenHeight + chrSize * 3) * one || x self <= -chrSize * one 
  • lang/haskell/nario/Actor/Koura.hs

    r20925 r20943  
    4444 
    4545        render self imgres scrx sur = do 
    46                 putimg sur imgres imgtype ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    47                 return () 
    48                 where 
    49                         imgtype = ImgKoura 
     46                putimg sur imgres ImgKoura ((x self) `div` one - chrSize `div` 2 - scrx) ((y self) `div` one - ofsH - 8) 
    5047 
    5148        bDead self = y self >= (screenHeight + chrSize * 3) * one || x self <= -chrSize * one 
  • lang/haskell/nario/Actor/Kuribo.hs

    r20925 r20943  
    3232                        (x', y', vx', vy') = updateActorBase fld (x self, y self, vx self, vy self) 
    3333 
    34         render self imgres scrx sur = do 
     34        render self imgres scrx sur = 
    3535                putimg sur imgres imgtype (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8) 
    36                 return () 
    3736                where 
    3837                        imgtype = [ImgKuri0, ImgKuri1] !! (cnt self `mod` 16 `div` 8) 
     
    6665        update fld self = (self { ccnt = ccnt self + 1 }, []) 
    6766 
    68         render self imgres scrx sur = do 
     67        render self imgres scrx sur = 
    6968                putimg sur imgres ImgKuriDead (sx self - scrx) (sy self - 7 - 8) 
    70                 return () 
    7169 
    7270        bDead self = ccnt self >= frameRate `div` 2 
  • lang/haskell/nario/Actor/Nokonoko.hs

    r20925 r20943  
    3333                        (x', y', vx', vy') = updateActorBase fld (x self, y self, vx self, vy self) 
    3434 
    35         render self imgres scrx sur = do 
     35        render self imgres scrx sur = 
    3636                putimg sur imgres imgtype (x self `div` one - chrSize `div` 2 - scrx) (y self `div` one - ofsH - 8) 
    37                 return () 
    3837                where 
    3938                        imgtype = imgtbl !! (cnt self `mod` 16 `div` 8) 
  • lang/haskell/nario/Actor/ScoreAdd.hs

    r20925 r20943  
    2626        update _ self = (self { sy = sy self + vy, cnt = cnt self + 1 }, []) 
    2727 
    28         render self imgres scrx sur = do 
     28        render self imgres scrx sur = 
    2929                putimg sur imgres imgtype (sx self - scrx) (sy self) 
    30                 return () 
    3130                where 
    3231                        imgtype = case pnt self of 
  • lang/haskell/nario/AppUtil.hs

    r20925 r20943  
    1 module AppUtil where 
     1module AppUtil ( 
     2        KeyState(..), 
     3        isPressing, 
     4        KeyProc, 
     5        keyProc, 
     6 
     7        PadBtn(..), 
     8        padPressing, 
     9        padPressed, 
     10 
     11        ImageResource, 
     12        loadImageResource, 
     13        releaseImageResource, 
     14        getImageSurface, 
     15        putimg, 
     16 
     17        cellCrd, 
     18        Rect(..), 
     19        ishit 
     20) where 
    221 
    322import Multimedia.SDL (Surface, SDLKey(..), loadBMP, freeSurface, surfacePixelFormat, displayFormat, pfPalette, setColorKey, SurfaceFlag(..), blitSurface, pt) 
     
    928-- キーボード処理 
    1029 
    11 data PadBtn = 
    12         PadU | PadD | PadL | PadR | PadA | PadB 
    13         deriving (Eq, Show, Enum) 
    14  
    1530data KeyState = 
    1631        Pushed | Pushing | Released | Releasing 
    17         deriving (Eq, Show) 
     32        deriving (Eq) 
    1833 
    19 isPressed Pushed  = True 
    20 isPressed Pushing = True 
    21 isPressed _       = False 
     34isPressing Pushed  = True 
     35isPressing Pushing = True 
     36isPressing _       = False 
    2237 
    23 type KeyProc = PadBtn -> KeyState 
     38type KeyProc = SDLKey -> KeyState 
    2439 
    25 keyProc bef cur gk 
     40keyProc :: [SDLKey] -> [SDLKey] -> KeyProc 
     41keyProc bef cur k 
    2642        | not bp && not cp = Releasing 
    2743        | not bp && cp     = Pushed 
     
    2945        | bp     && cp     = Pushing 
    3046        where 
    31                 bp = any (flip elem bef) phykeys 
    32                 cp = any (flip elem cur) phykeys 
    33                 phykeys = mapPhyKey gk 
     47                bp = k `elem` bef 
     48                cp = k `elem` cur 
    3449 
    35 mapPhyKey PadU = [SDLK_UP, SDLK_i] 
    36 mapPhyKey PadD = [SDLK_DOWN, SDLK_k] 
    37 mapPhyKey PadL = [SDLK_LEFT, SDLK_j] 
    38 mapPhyKey PadR = [SDLK_RIGHT, SDLK_l] 
    39 mapPhyKey PadA = [SDLK_SPACE, SDLK_z] 
    40 mapPhyKey PadB = [SDLK_LSHIFT, SDLK_RSHIFT] 
     50 
     51-- パッド 
     52 
     53data PadBtn = 
     54        PadU | PadD | PadL | PadR | PadA | PadB 
     55        deriving (Eq) 
     56 
     57padPressing kp btn = any (isPressing . kp) $ mapSDLKey btn 
     58padPressed kp btn = any ((== Pushed) . kp) $ mapSDLKey btn 
     59 
     60mapSDLKey PadU = [SDLK_UP, SDLK_i] 
     61mapSDLKey PadD = [SDLK_DOWN, SDLK_k] 
     62mapSDLKey PadL = [SDLK_LEFT, SDLK_j] 
     63mapSDLKey PadR = [SDLK_RIGHT, SDLK_l] 
     64mapSDLKey PadA = [SDLK_SPACE, SDLK_z] 
     65mapSDLKey PadB = [SDLK_LSHIFT, SDLK_RSHIFT] 
    4166 
    4267 
  • lang/haskell/nario/Main.hs

    r20925 r20943  
    8686 
    8787 
    88 -- キー入力を処理して描画コマンドを返す 
     88-- キー入力全体を処理して描画コマンド列を返す 
    8989process :: [[SDLKey]] -> IO [Scr] 
    9090process kss = do 
     
    9393 
    9494        let tmpscrs = doTitle fldmap kss 
    95  
    96         let scrs = map (\scr sur -> scr imgres sur >> flipSurface sur >> return ()) $ tmpscrs 
    97         return $ scrs ++ [(\sur -> do {releaseImageResource imgres})] 
    98  
     95        let scrs = zipWith (common imgres) tmpscrs kss 
     96        return $ scrs ++ [final imgres] 
     97 
     98        where 
     99                -- 共通動作 
     100                common imgres scr ks sur = do 
     101                        scr imgres sur 
     102                        if SDLK_s `elem` ks 
     103                                then saveBMP sur "ss.bmp" >> return () 
     104                                else return () 
     105                        flipSurface sur 
     106                        return () 
     107                -- 後始末 
     108                final imgres sur = releaseImageResource imgres 
    99109 
    100110-- タイトル 
     
    172182                -- 更新 
    173183                updateProc :: KeyProc -> GameGame -> (ImageResource -> Scr, GameGame) 
    174                 updateProc kp gs = (renderProc gs', gs') 
     184                updateProc kp gs = (scr', gs') 
    175185                        where 
    176186                                time' = max 0 (time gs - 1) 
     
    186196                                gstmp = gs { pl = pl'', fld = fld', actors = actors'', time = time' } 
    187197                                gs' = procEvent gstmp (plev ++ ev' ++ screv' ++ ev'') 
     198                                scr' = renderProc gs' 
    188199 
    189200                initialState = GameGame { pl = newPlayer, fld = fldmap, actors = [], time = 400 * timeBase } 
  • lang/haskell/nario/Player.hs

    r20925 r20943  
    2626 
    2727import Util 
    28 import AppUtil (KeyProc, isPressed, PadBtn(..), cellCrd, KeyState(..), getImageSurface, Rect(..), putimg) 
     28import AppUtil (KeyProc, padPressed, padPressing, PadBtn(..), cellCrd, KeyState(..), getImageSurface, Rect(..), putimg) 
    2929import Const 
    3030import Images 
     
    132132                x' = max xmin $ (x self) + vx' 
    133133 
    134                 padd = if isPressed (kp PadD) then True else False 
    135                 padl = if isPressed (kp PadL) then 1 else 0 
    136                 padr = if isPressed (kp PadR) then 1 else 0 
     134                padd = if padPressing kp PadD then True else False 
     135                padl = if padPressing kp PadL then 1 else 0 
     136                padr = if padPressing kp PadR then 1 else 0 
    137137                maxspd 
    138138                        | not $ stand self      = walkVx `div` 2 
    139                         | isPressed (kp PadB)   = runVx 
     139                        | padPressing kp PadB   = runVx 
    140140                        | otherwise                             = walkVx 
    141141                nowacc 
    142                         | isPressed (kp PadB)   = acc2 
     142                        | padPressing kp PadB   = acc2 
    143143                        | otherwise                             = acc 
    144144                xmin = (scrx self + chrSize `div` 2) * one 
     
    237237doJump :: KeyProc -> Player -> Player 
    238238doJump kp self 
    239         | stand self && kp PadA == Pushed       = self { vy = vy', stand = False, pat = patJump } 
     239        | stand self && padPressed kp PadA      = self { vy = vy', stand = False, pat = patJump } 
    240240        | otherwise                                                     = self 
    241241        where 
     
    257257        moveY $ scroll self $ checkX fld $ moveX kp self 
    258258        where 
    259                 moveY = checkCeil fld . doJump kp . checkFloor fld . fall (isPressed $ kp PadA) 
     259                moveY = checkCeil fld . doJump kp . checkFloor fld . fall (padPressing kp PadA) 
    260260 
    261261-- 死亡時 
  • lang/haskell/nario/Util.hs

    r20925 r20943  
    88 
    99-- けつの n 個取り出し 
    10 lastN n xs = loop n [] xs 
     10lastN n xs = supply n [] xs 
    1111        where 
    12                 loop _ acc [] = acc 
    13                 loop 0 acc (x:xs) = loop 0 (tail acc ++ [x]) xs 
    14                 loop n acc (x:xs) = loop (n-1) (acc ++ [x]) xs 
     12                supply _ acc [] = acc 
     13                supply 0 acc xs = queue acc xs 
     14                supply n acc (x:xs) = supply (n-1) (acc ++ [x]) xs 
     15                queue acc [] = acc 
     16                queue acc (x:xs) = queue (tail acc ++ [x]) xs 
    1517 
    1618-- 数値の符号を返す