Changeset 20691 for lang/haskell/nario/Player.hs
- Timestamp:
- 10/04/08 18:09:41 (3 months ago)
- Files:
-
- 1 modified
-
lang/haskell/nario/Player.hs (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/haskell/nario/Player.hs
r20680 r20691 9 9 getScrollPos, 10 10 getPlayerYPos, 11 getPlayerVY, 11 12 getPlayerHitRect, 12 13 getPlayerMedal, 13 14 getPlayerScore, 14 15 getPlayerType, 15 setPlayerType 16 setPlayerType, 17 setPlayerDamage, 18 stampPlayer 16 19 ) where 17 20 18 21 import Multimedia.SDL (blitSurface, pt) 22 import Data.Bits ((.&.)) 19 23 20 24 import Util … … 34 38 scrollMaxX = 8 * chrSize 35 39 gravity2 = one `div` 4 -- Aを長押ししたときの重力 36 40 stampVy = -8 * gravity 41 undeadFrame = frameRate * 2 42 43 -- 種類 37 44 data PlayerType = SmallNario | SuperNario | FireNario 38 45 deriving (Eq) 39 46 47 -- 状態 48 data PlayerState = Normal | Dead 49 deriving (Eq) 50 51 -- 構造体 40 52 data Player = Player { 41 53 pltype :: PlayerType, 54 plstate :: PlayerState, 42 55 x :: Int, 43 56 y :: Int, … … 46 59 scrx :: Int, 47 60 stand :: Bool, 61 undeadCount :: Int, 48 62 49 63 medal :: Int, … … 57 71 newPlayer = Player { 58 72 pltype = SmallNario, 73 plstate = Normal, 59 74 x = 3 * chrSize * one, 60 75 y = 13 * chrSize * one, … … 63 78 scrx = 0, 64 79 stand = False, 80 undeadCount = 0, 65 81 66 82 medal = 0, … … 80 96 patSit = patSlip + 1 81 97 patShot = patSit + 1 98 patDead = patShot + 2 82 99 83 100 imgTableSmall = [ … … 102 119 else self' 103 120 where 104 ax = (-padl + padr) * acc121 ax = if padd then 0 else (-padl + padr) * acc 105 122 vx' 106 123 | ax /= 0 = rangeadd (vx self) ax (-maxspd) maxspd … … 114 131 scrollPos = (max vx' 0) * (scrollMaxX - scrollMinX) `div` runVx + scrollMinX 115 132 133 padd = if isPressed (kp PadD) then True else False 116 134 padl = if isPressed (kp PadL) then 1 else 0 117 135 padr = if isPressed (kp PadR) then 1 else 0 … … 130 148 1 -> 1 131 149 pat' 150 | padd && pltype self /= SmallNario = patSit 132 151 | vx' == 0 = patStop 133 152 | vx' > 0 && lr' == 0 = patSlip … … 158 177 159 178 -- 重力による落下 160 fall :: KeyProc-> Player -> Player161 fall kpself179 fall :: Bool -> Player -> Player 180 fall abtn self 162 181 | stand self = self 163 182 | otherwise = self { y = y', vy = vy' } 164 183 where 165 184 ay 166 | vy self < 0 && isPressed (kp PadA)= gravity2167 | otherwise = gravity185 | vy self < 0 && abtn = gravity2 186 | otherwise = gravity 168 187 vy' = min maxVy $ vy self + ay 169 188 y' = y self + vy' … … 211 230 updatePlayer :: KeyProc -> Field -> Player -> (Player, [Event]) 212 231 updatePlayer kp fld self = 232 case plstate self of 233 Normal -> updateNormal kp fld self' 234 Dead -> updateDead kp fld self' 235 where 236 self' = decUndead self 237 decUndead pl = pl { undeadCount = max 0 $ undeadCount pl - 1 } 238 239 -- 通常時 240 updateNormal :: KeyProc -> Field -> Player -> (Player, [Event]) 241 updateNormal kp fld self = 213 242 moveY $ checkX fld $ moveX kp self 214 243 where 215 moveY = checkCeil fld . doJump kp . checkFloor fld . fall kp 244 moveY = checkCeil fld . doJump kp . checkFloor fld . fall (isPressed $ kp PadA) 245 246 -- 死亡時 247 updateDead :: KeyProc -> Field -> Player -> (Player, [Event]) 248 updateDead kp fld self = (fall False self, []) 216 249 217 250 -- スクロール位置取得 … … 223 256 getPlayerYPos = (`div` one) . y 224 257 258 -- Y速度取得 259 getPlayerVY :: Player -> Int 260 getPlayerVY = vy 261 225 262 -- 当たり判定用矩形 226 263 getPlayerHitRect :: Player -> Rect … … 246 283 setPlayerType t self = self { pltype = t } 247 284 285 -- ダメージを与える 286 setPlayerDamage :: Player -> Player 287 setPlayerDamage self 288 | undeadCount self > 0 = self 289 | pltype self == SmallNario = self { plstate = Dead, pat = patDead, vy = jumpVy, stand = False } 290 | otherwise = self { pltype = SmallNario, undeadCount = undeadFrame } 291 292 -- 敵を踏み潰した 293 stampPlayer :: Player -> Player 294 stampPlayer self = self { vy = stampVy } 295 248 296 -- 描画 249 297 renderPlayer sur imgres scrx self = do 250 blitSurface (getImageSurface imgres imgtype) Nothing sur pos 298 if undeadCount self == 0 || (undeadCount self .&. 1) /= 0 299 then blitSurface (getImageSurface imgres imgtype) Nothing sur pos >> return () 300 else return () 251 301 where 252 302 pos = case pltype self of 253 303 SmallNario -> pt sx $ sy - chrSize + 1 254 304 otherwise -> pt sx $ sy - chrSize * 2 + 1 255 imgtype = imgtbl !! lr self !! pat self 305 imgtype 306 | plstate self == Dead = ImgNarioDead 307 | otherwise = imgtbl !! lr self !! pat self 256 308 imgtbl = case pltype self of 257 309 SmallNario -> imgTableSmall
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)