feat: dash doesnot affect by gravity and will cancel jump
This commit is contained in:
		
							parent
							
								
									bc347270a6
								
							
						
					
					
						commit
						cf3c3cf860
					
				| 
						 | 
					@ -38,6 +38,14 @@ export default class Jump extends InAir {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(this.owner.onCeiling){
 | 
				
			||||||
 | 
								this.parent.velocity.y = 0;
 | 
				
			||||||
 | 
								this.finished(PlayerStates.FALL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// If we're falling, go to the fall state
 | 
				
			||||||
 | 
							if(this.parent.velocity.y >= 0){
 | 
				
			||||||
 | 
								this.finished(PlayerStates.FALL);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (!this.jumpTimer.isStopped() && !this.jumpTimer.isPaused() && InputWrapper.isJumpPressed()) {
 | 
							if (!this.jumpTimer.isStopped() && !this.jumpTimer.isPaused() && InputWrapper.isJumpPressed()) {
 | 
				
			||||||
			this.parent.velocity.y = -400;
 | 
								this.parent.velocity.y = -400;
 | 
				
			||||||
| 
						 | 
					@ -46,13 +54,6 @@ export default class Jump extends InAir {
 | 
				
			||||||
			this.jumpTimer.pause();
 | 
								this.jumpTimer.pause();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if(this.owner.onCeiling){
 | 
					 | 
				
			||||||
			this.parent.velocity.y = 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// If we're falling, go to the fall state
 | 
					 | 
				
			||||||
		if(this.parent.velocity.y >= 0){
 | 
					 | 
				
			||||||
			this.finished(PlayerStates.FALL);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		super.update(deltaT);
 | 
							super.update(deltaT);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,23 +58,26 @@ export default abstract class PlayerState extends State {
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	update(deltaT: number): void {
 | 
						update(deltaT: number): void {
 | 
				
			||||||
		// Do gravity
 | 
							
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (this.positionTimer.isStopped()){
 | 
							if (this.positionTimer.isStopped()){
 | 
				
			||||||
			this.emitter.fireEvent(Player_Events.PLAYER_MOVE, {position: this.owner.position.clone()});
 | 
								this.emitter.fireEvent(Player_Events.PLAYER_MOVE, {position: this.owner.position.clone()});
 | 
				
			||||||
			this.positionTimer.start();
 | 
								this.positionTimer.start();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (InputWrapper.getState() === GameState.GAMING) {
 | 
				
			||||||
 | 
								// Do gravity
 | 
				
			||||||
 | 
								(<AnimatedSprite>this.parent.owner).animation.resume();
 | 
				
			||||||
 | 
								this.parent.velocity.y += this.gravity*deltaT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Do dash
 | 
				
			||||||
			if(InputWrapper.isDashJustPressed()){
 | 
								if(InputWrapper.isDashJustPressed()){
 | 
				
			||||||
				this.doDash();
 | 
									this.doDash();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (!PlayerState.dashTimer.isStopped()) {
 | 
								if (!PlayerState.dashTimer.isStopped()) {
 | 
				
			||||||
				this.parent.velocity.x = (<Sprite>this.owner).invertX ? -800 : 800;
 | 
									this.parent.velocity.x = (<Sprite>this.owner).invertX ? -800 : 800;
 | 
				
			||||||
 | 
									this.parent.velocity.y = 0;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		if (InputWrapper.getState() === GameState.GAMING) {
 | 
					 | 
				
			||||||
			(<AnimatedSprite>this.parent.owner).animation.resume();
 | 
					 | 
				
			||||||
			this.parent.velocity.y += this.gravity*deltaT;
 | 
					 | 
				
			||||||
			this.owner.move(this.parent.velocity.scaled(deltaT));
 | 
								this.owner.move(this.parent.velocity.scaled(deltaT));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user