Show
Ignore:
Timestamp:
10/04/08 14:32:30 (3 months ago)
Author:
mokehehe
Message:

プレーヤーとの当たり判定追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/haskell/nario/Main.hs

    r20670 r20673  
    7676                pl :: Player, 
    7777                fld :: Field, 
    78                 actors :: [ObjWrapper], 
     78                actors :: [ActorWrapper], 
    7979                time :: Int 
    8080        } 
     
    125125                        | otherwise             = Nothing 
    126126 
     127 
     128 
     129-- 当たり判定 
     130hitcheck :: Player -> [ActorWrapper] -> (Player, [ActorWrapper]) 
     131hitcheck 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 
    127146-- ゲーム 
    128147doGame :: Field -> [[SDLKey]] -> [ImageResource -> Scr] 
     
    152171                                ev' = concatMap snd actors_updates 
    153172 
    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' } 
    155176                                gs' = procEvent gstmp (plev ++ ev' ++ screv') 
    156177 
    157178                initialState = GameGame { pl = newPlayer, fld = fldmap, actors = [], time = 400 * one } 
    158179 
     180-- ゲームオーバー 
    159181doGameOver fldmap kss = doTitle fldmap kss 
    160182 
     
    170192                                c = fieldRef (fld gs) cx cy 
    171193                                items 
    172                                         | c == 'K'      = [ObjWrapper $ newKinoko cx cy] 
     194                                        | c == 'K'      = [ActorWrapper $ newKinoko cx cy] 
    173195                                        | otherwise     = [] 
    174                                 actors' = actors gs ++ [ObjWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] ++ items 
     196                                actors' = actors gs ++ [ActorWrapper $ newAnimBlock cx cy $ fieldRef (fld gs) cx cy] ++ items 
    175197                                fld' = fieldSet (fld gs) cx cy '*' 
    176198                proc gs (EvSetField cx cy c) = gs { fld = fieldSet (fld gs) cx cy c } 
     
    178200                        where 
    179201                                ene = case c of 
    180                                         'k'     -> ObjWrapper $ newKuribo cx cy 
    181                                         'n'     -> ObjWrapper $ newNokonoko cx cy 
     202                                        'k'     -> ActorWrapper $ newKuribo cx cy 
     203                                        'n'     -> ActorWrapper $ newNokonoko cx cy 
    182204 
    183205