Changeset 20086 for lang/haskell
- Timestamp:
- 09/28/08 10:42:38 (8 weeks ago)
- Location:
- lang/haskell/nario
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Player.hs
r20045 r20086 75 75 ax = (-padl + padr) * acc 76 76 vx' 77 | ax /= 0 = rangeadd (vx player) ax (-maxspd) maxspd 78 | otherwise = friction (vx player) acc 77 | ax /= 0 = rangeadd (vx player) ax (-maxspd) maxspd 78 | (stand player) = friction (vx player) acc 79 | otherwise = friction (vx player) (acc `div` 2) 79 80 x' = max xmin $ (x player) + vx' 80 81 scrx' … … 85 86 padr = if isPressed (kp PadR) then 1 else 0 86 87 maxspd 88 | not $ stand player = maxVx `div` 2 87 89 | isPressed (kp PadB) = maxVx * 2 88 90 | otherwise = maxVx … … 105 107 106 108 107 -- ジャンプ中 108 jump :: Field -> Player -> Player 109 jump fld player = 110 player { y = y', vy = vy', stand = stand' } 109 -- 横移動チェック 110 checkX :: Field -> Player -> Player 111 checkX fld player 112 | dir == 0 = check (-1) $ check 1 $ player 113 | otherwise = check dir $ player 111 114 where 112 vytmp = min maxVy $ (vy player) + gravity 113 ytmp = (y player) + vytmp 115 dir = sgn $ vx player 116 check dx player 117 | isBlock $ fieldRef fld cx cy = player { x = (x player) - dx * one, vx = 0 } 118 | otherwise = player 119 where 120 cx = cellCrd (x player + dx * chrSize `div` 2 * one) 121 cy = cellCrd (y player - chrSize `div` 2 * one) 114 122 115 y' = if isGround ytmp then yground ytmp else ytmp116 vy' = if isGround ytmp then 0 else vytmp117 stand' = isGround ytmp118 123 119 isGround y = isBlock $ fieldRef fld (cellCrd (x player)) (cellCrd y) 124 -- 重力による落下 125 fall :: Player -> Player 126 fall player 127 | stand player = player 128 | otherwise = player { y = y', vy = vy' } 129 where 130 vy' = min maxVy $ vy player + gravity 131 y' = y player + vy' 132 133 134 -- 床をチェック 135 checkFloor :: Field -> Player -> Player 136 checkFloor fld player 137 | stand' = player { stand = stand', y = ystand, vy = 0 } 138 | otherwise = player { stand = stand' } 139 where 140 stand' = isGround $ y player 141 ystand = (cellCrd $ y player) * (chrSize * one) 142 143 isGround y = isBlock $ fieldRef fld (cellCrd $ x player) (cellCrd y) 144 145 146 -- 上をチェック 147 checkCeil :: Field -> Player -> Player 148 checkCeil fld player 149 | stand player || vy player >= 0 || not isCeil = player 150 | otherwise = player { vy = 0 } 151 where 152 ytmp = y player - one * chrSize 153 154 isCeil = isBlock $ fieldRef fld (cellCrd $ x player) (cellCrd ytmp) 120 155 yground y = (cellCrd y) * (chrSize * one) 121 156 122 157 123 -- 通常時:地面をチェック 124 checkFall :: KeyProc -> Field -> Player -> Player 125 checkFall kp fld player = 126 player { stand = stand', vy = vy', pat = pat' } 127 where 128 ytmp = (y player) + one 158 -- ジャンプする? 159 doJump :: KeyProc -> Player -> Player 160 doJump kp player 161 | stand player && kp PadA == Pushed = player { vy = jumpVy, stand = False, pat = patJump } 162 | otherwise = player 129 163 130 stand'131 | isGround ytmp = not dojump132 | otherwise = False -- 落下開始133 vy'134 | not stand' && dojump = jumpVy135 | otherwise = 0136 pat'137 | dojump = patJump138 | otherwise = pat player139 140 dojump = kp PadA == Pushed141 142 isGround y = isBlock $ fieldRef fld (cellCrd (x player)) (cellCrd y)143 yground y = (cellCrd y) * (chrSize * one)144 164 145 165 -- 更新処理 146 166 updatePlayer :: KeyProc -> Field -> Player -> Player 147 167 updatePlayer kp fld player = 148 moveY $ moveX kp player168 moveY $ checkX fld $ moveX kp player 149 169 where 150 170 moveY 151 | (stand player) = checkFall kp fld152 | otherwise = jump fld171 | stand player = doJump kp . checkFloor fld . fall 172 | otherwise = checkCeil fld . checkFloor fld . fall 153 173 154 174 -- スクロール位置取得 -
lang/haskell/nario/Util.hs
r20045 r20086 11 11 12 12 -- ユーティリティ関数 13 14 -- 符号を返す 15 sgn x 16 | x > 0 = 1 17 | x < 0 = -1 18 | otherwise = 0 13 19 14 20 -- x に d を加算した結果が x0~x1 の範囲内を超えないようにする
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)