Show
Ignore:
Timestamp:
10/04/08 16:01:22 (3 months ago)
Author:
mokehehe
Message:

きのこを取って巨大化
花を取ってファイヤー化(ショットはまだ撃てない)

Files:
1 modified

Legend:

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

    r20673 r20680  
    33module Player ( 
    44        Player(..), 
     5        PlayerType(..), 
    56        newPlayer, 
    67        updatePlayer, 
     
    1011        getPlayerHitRect, 
    1112        getPlayerMedal, 
    12         getPlayerScore 
     13        getPlayerScore, 
     14        getPlayerType, 
     15        setPlayerType 
    1316) where 
    1417 
     
    3235gravity2 = one `div` 4          -- Aを長押ししたときの重力 
    3336 
     37data PlayerType = SmallNario | SuperNario | FireNario 
     38        deriving (Eq) 
     39 
    3440data Player = Player { 
     41        pltype :: PlayerType, 
    3542        x :: Int, 
    3643        y :: Int, 
     
    4956 
    5057newPlayer = Player { 
     58        pltype = SmallNario, 
    5159        x = 3 * chrSize * one, 
    5260        y = 13 * chrSize * one, 
     
    7078patJump = patWalk + walkPatNum 
    7179patSlip = patJump + 1 
    72  
    73 imgTable = [ 
    74         [ImgNarioLStand, ImgNarioLWalk1, ImgNarioLWalk2, ImgNarioLWalk3, ImgNarioLJump, ImgNarioLSlip], 
    75         [ImgNarioRStand, ImgNarioRWalk1, ImgNarioRWalk2, ImgNarioRWalk3, ImgNarioRJump, ImgNarioRSlip] 
     80patSit = patSlip + 1 
     81patShot = patSit + 1 
     82 
     83imgTableSmall = [ 
     84        [ImgNarioLStand, ImgNarioLWalk1, ImgNarioLWalk2, ImgNarioLWalk3, ImgNarioLJump, ImgNarioLSlip, ImgNarioLStand], 
     85        [ImgNarioRStand, ImgNarioRWalk1, ImgNarioRWalk2, ImgNarioRWalk3, ImgNarioRJump, ImgNarioRSlip, ImgNarioRStand] 
     86        ] 
     87imgTableSuper = [ 
     88        [ImgSNarioLStand, ImgSNarioLWalk1, ImgSNarioLWalk2, ImgSNarioLWalk3, ImgSNarioLJump, ImgSNarioLSlip, ImgSNarioLSit], 
     89        [ImgSNarioRStand, ImgSNarioRWalk1, ImgSNarioRWalk2, ImgSNarioRWalk3, ImgSNarioRJump, ImgSNarioRSlip, ImgSNarioRSit] 
     90        ] 
     91imgTableFire = [ 
     92        [ImgFNarioLStand, ImgFNarioLWalk1, ImgFNarioLWalk2, ImgFNarioLWalk3, ImgFNarioLJump, ImgFNarioLSlip, ImgFNarioLSit, ImgFNarioLShot], 
     93        [ImgFNarioRStand, ImgFNarioRWalk1, ImgFNarioRWalk2, ImgFNarioRWalk3, ImgFNarioRJump, ImgFNarioRSlip, ImgFNarioRSit, ImgFNarioRShot] 
    7694        ] 
    7795 
     
    7997-- 横移動 
    8098moveX :: KeyProc -> Player -> Player 
    81 moveX kp player = 
    82         if (stand player) 
    83                 then player' { lr = lr', pat = pat', anm = anm' } 
    84                 else player' 
     99moveX kp self = 
     100        if (stand self) 
     101                then self' { lr = lr', pat = pat', anm = anm' } 
     102                else self' 
    85103        where 
    86104                ax = (-padl + padr) * acc 
    87105                vx' 
    88                         | ax /= 0                       = rangeadd (vx player) ax (-maxspd) maxspd 
    89                         | stand player          = friction (vx player) acc 
    90                         | otherwise                     = vx player 
    91                 x' = max xmin $ (x player) + vx' 
     106                        | ax /= 0                       = rangeadd (vx self) ax (-maxspd) maxspd 
     107                        | stand self            = friction (vx self) acc 
     108                        | otherwise                     = vx self 
     109                x' = max xmin $ (x self) + vx' 
    92110                scrx' 
    93                         | vx' > 0 && (x' - (scrx player)) `div` one > scrollPos = (scrx player) + vx' 
    94                         | otherwise                                                                                             = (scrx player) 
     111                        | vx' > 0 && (x' - (scrx self)) `div` one > scrollPos   = (scrx self) + vx' 
     112                        | otherwise                                                                                             = (scrx self) 
    95113 
    96114                scrollPos = (max vx' 0) * (scrollMaxX - scrollMinX) `div` runVx + scrollMinX 
     
    99117                padr = if isPressed (kp PadR) then 1 else 0 
    100118                maxspd 
    101                         | not $ stand player    = walkVx `div` 2 
     119                        | not $ stand self      = walkVx `div` 2 
    102120                        | isPressed (kp PadB)   = walkVx * 2 
    103121                        | otherwise                             = walkVx 
    104                 xmin = (scrx player) + chrSize `div` 2 * one 
    105  
    106                 player' = player { x = x', vx = vx', scrx = scrx' } 
     122                xmin = (scrx self) + chrSize `div` 2 * one 
     123 
     124                self' = self { x = x', vx = vx', scrx = scrx' } 
    107125 
    108126                lr' = 
    109127                        case (-padl + padr) of 
    110                                 0       -> lr player 
     128                                0       -> lr self 
    111129                                -1      -> 0 
    112130                                1       -> 1 
     
    118136                anm' 
    119137                        | vx' == 0              = 0 
    120                         | otherwise             = ((anm player) + (abs vx')) `mod` (walkPatNum * anmCnt) 
     138                        | otherwise             = ((anm self) + (abs vx')) `mod` (walkPatNum * anmCnt) 
    121139                anmCnt = walkVx * 3 
    122140 
     
    124142-- 横移動チェック 
    125143checkX :: Field -> Player -> Player 
    126 checkX fld player 
    127         | dir == 0      = check (-1) $ check 1 $ player 
    128         | otherwise = check dir $ player 
    129         where 
    130                 dir = sgn $ vx player 
    131                 check dx player 
    132                         | isBlock $ fieldRef fld cx cy  = player { x = (x player) - dx * one, vx = 0 } 
    133                         | otherwise                                             = player 
     144checkX fld self 
     145        | dir == 0      = check (-1) $ check 1 $ self 
     146        | otherwise = check dir $ self 
     147        where 
     148                dir = sgn $ vx self 
     149                check dx self 
     150                        | isBlock $ fieldRef fld cx cy  = self { x = (x self) - dx * one, vx = 0 } 
     151                        | otherwise                                             = self 
    134152                        where 
    135                                 cx = cellCrd (x player + ofsx dx) 
    136                                 cy = cellCrd (y player - chrSize `div` 2 * one) 
     153                                cx = cellCrd (x self + ofsx dx) 
     154                                cy = cellCrd (y self - chrSize `div` 2 * one) 
    137155                                ofsx (-1) = -6 * one 
    138156                                ofsx   1  =  5 * one 
     
    141159-- 重力による落下 
    142160fall :: KeyProc -> Player -> Player 
    143 fall kp player 
    144         | stand player  = player 
    145         | otherwise             = player { y = y', vy = vy' } 
     161fall kp self 
     162        | stand self    = self 
     163        | otherwise             = self { y = y', vy = vy' } 
    146164        where 
    147165                ay 
    148                         | vy player < 0 && isPressed (kp PadA)  = gravity2 
     166                        | vy self < 0 && isPressed (kp PadA)    = gravity2 
    149167                        | otherwise                                                             = gravity 
    150                 vy' = min maxVy $ vy player + ay 
    151                 y' = y player + vy' 
     168                vy' = min maxVy $ vy self + ay 
     169                y' = y self + vy' 
    152170 
    153171 
    154172-- 床をチェック 
    155173checkFloor :: Field -> Player -> Player 
    156 checkFloor fld player 
    157         | stand'        = player { stand = stand', y = ystand, vy = 0 } 
    158         | otherwise     = player { stand = stand' } 
     174checkFloor fld self 
     175        | stand'        = self { stand = stand', y = ystand, vy = 0 } 
     176        | otherwise     = self { stand = stand' } 
    159177        where 
    160178                stand' 
    161                         | vy player >= 0        = isGround (-6) || isGround 5 
    162                         | otherwise                     = stand player 
    163                 ystand = (cellCrd $ y player) * (chrSize * one) 
    164  
    165                 isGround ofsx = isBlock $ fieldRef fld (cellCrd $ x player + ofsx * one) (cellCrd (y player)) 
     179                        | vy self >= 0  = isGround (-6) || isGround 5 
     180                        | otherwise                     = stand self 
     181                ystand = (cellCrd $ y self) * (chrSize * one) 
     182 
     183                isGround ofsx = isBlock $ fieldRef fld (cellCrd $ x self + ofsx * one) (cellCrd (y self)) 
    166184 
    167185-- 上をチェック 
    168186checkCeil :: Field -> Player -> (Player, [Event]) 
    169 checkCeil fld player 
    170         | stand player || vy player >= 0 || not isCeil  = (player, []) 
    171         | otherwise = (player { vy = 0, score = (score player) + 10 }, [EvHitBlock ImgBlock2 cx cy]) 
    172         where 
    173                 ytmp = y player - one * chrSize 
    174  
    175                 cx = cellCrd $ x player 
     187checkCeil fld self 
     188        | stand self || vy self >= 0 || not isCeil      = (self, []) 
     189        | otherwise = (self { vy = 0, score = (score self) + 10 }, [EvHitBlock ImgBlock2 cx cy (pltype self /= SmallNario)]) 
     190        where 
     191                yofs = case pltype self of 
     192                        SmallNario      -> 15 
     193                        SuperNario      -> 30 
     194                        FireNario       -> 30 
     195                ytmp = y self - yofs * one 
     196 
     197                cx = cellCrd $ x self 
    176198                cy = cellCrd ytmp 
    177199                isCeil = isBlock $ fieldRef fld cx cy 
     
    181203-- ジャンプする? 
    182204doJump :: KeyProc -> Player -> Player 
    183 doJump kp player 
    184         | stand player && kp PadA == Pushed     = player { vy = jumpVy, stand = False, pat = patJump } 
    185         | otherwise                                                     = player 
     205doJump kp self 
     206        | stand self && kp PadA == Pushed       = self { vy = jumpVy, stand = False, pat = patJump } 
     207        | otherwise                                                     = self 
    186208 
    187209 
    188210-- 更新処理 
    189211updatePlayer :: KeyProc -> Field -> Player -> (Player, [Event]) 
    190 updatePlayer kp fld player = 
    191         moveY $ checkX fld $ moveX kp player 
     212updatePlayer kp fld self = 
     213        moveY $ checkX fld $ moveX kp self 
    192214        where 
    193215                moveY = checkCeil fld . doJump kp . checkFloor fld . fall kp 
     
    195217-- スクロール位置取得 
    196218getScrollPos :: Player -> Int 
    197 getScrollPos player = (scrx player) `div` one 
     219getScrollPos self = (scrx self) `div` one 
    198220 
    199221-- Y座標取得 
     
    216238getPlayerScore = score 
    217239 
     240-- タイプ取得 
     241getPlayerType :: Player -> PlayerType 
     242getPlayerType = pltype 
     243 
     244-- タイプ設定 
     245setPlayerType :: PlayerType -> Player -> Player 
     246setPlayerType t self = self { pltype = t } 
     247 
    218248-- 描画 
    219 renderPlayer sur imgres scrx player = do 
     249renderPlayer sur imgres scrx self = do 
    220250        blitSurface (getImageSurface imgres imgtype) Nothing sur pos 
    221251        where 
    222                 pos = pt ((x player) `div` one - chrSize `div` 2 - scrx) ((y player) `div` one - chrSize+1 - 8) 
    223                 imgtype = imgTable !! (lr player) !! (pat player) 
     252                pos = case pltype self of 
     253                        SmallNario      -> pt sx $ sy - chrSize + 1 
     254                        otherwise       -> pt sx $ sy - chrSize * 2 + 1 
     255                imgtype = imgtbl !! lr self !! pat self 
     256                imgtbl = case pltype self of 
     257                        SmallNario      -> imgTableSmall 
     258                        SuperNario      -> imgTableSuper 
     259                        FireNario       -> imgTableFire 
     260                sx = x self `div` one - chrSize `div` 2 - scrx 
     261                sy = y self `div` one - 8