* The object is on the ascending and descending part of the jump. * The object is considered falling when the jump continue to a lower position than the initial one.
| 2301 | * The object is considered falling when the jump continue to a lower position than the initial one. |
| 2302 | */ |
| 2303 | class Jumping implements State { |
| 2304 | private _behavior: PlatformerObjectRuntimeBehavior; |
| 2305 | private _currentJumpSpeed: number = 0; |
| 2306 | private _timeSinceCurrentJumpStart: number = 0; |
| 2307 | private _jumpingFirstDelta: boolean = false; |
| 2308 | |
| 2309 | constructor(behavior: PlatformerObjectRuntimeBehavior) { |
| 2310 | this._behavior = behavior; |
| 2311 | } |
| 2312 | |
| 2313 | getCurrentJumpSpeed() { |
| 2314 | return this._currentJumpSpeed; |
| 2315 | } |
| 2316 | |
| 2317 | setCurrentJumpSpeed(currentJumpSpeed: number) { |
| 2318 | this._currentJumpSpeed = currentJumpSpeed; |
| 2319 | } |
| 2320 | |
| 2321 | enter(from: State) { |
| 2322 | const behavior = this._behavior; |
| 2323 | this._timeSinceCurrentJumpStart = 0; |
| 2324 | behavior._jumpKeyHeldSinceJumpStart = true; |
| 2325 | |
| 2326 | if (from !== behavior._jumping && from !== behavior._falling) { |
| 2327 | this._jumpingFirstDelta = true; |
| 2328 | } |
| 2329 | |
| 2330 | behavior._canJump = false; |
| 2331 | this._currentJumpSpeed = behavior._jumpSpeed; |
| 2332 | behavior._currentFallSpeed = 0; |
| 2333 | } |
| 2334 | |
| 2335 | leave() { |
| 2336 | this._currentJumpSpeed = 0; |
| 2337 | } |
| 2338 | |
| 2339 | beforeUpdatingObstacles(timeDelta: float) {} |
| 2340 | |
| 2341 | checkTransitionBeforeX() {} |
| 2342 | |
| 2343 | beforeMovingX() {} |
| 2344 | |
| 2345 | checkTransitionBeforeY(timeDelta: float) { |
| 2346 | const behavior = this._behavior; |
| 2347 | // Go on a ladder |
| 2348 | behavior._checkTransitionOnLadder(); |
| 2349 | // Jumping |
| 2350 | behavior._checkTransitionJumping(); |
| 2351 | |
| 2352 | // Grabbing a platform |
| 2353 | if ( |
| 2354 | behavior._canGrabPlatforms && |
| 2355 | (behavior._requestedDeltaX !== 0 || behavior._canGrabWithoutMoving) && |
| 2356 | behavior._lastDeltaY >= 0 |
| 2357 | ) { |
| 2358 | behavior._checkGrabPlatform(); |
| 2359 | } |
| 2360 | } |
nothing calls this directly
no outgoing calls
no test coverage detected