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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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