feat: jump height depend on pressing time
This commit is contained in:
parent
a906d19842
commit
bc347270a6
|
@ -28,14 +28,10 @@ export default class Fall extends InAir {
|
||||||
this.owner.animation.playIfNotAlready("FALL", true);
|
this.owner.animation.playIfNotAlready("FALL", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO - testing doublejump, may have to move to InAir instead
|
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
|
||||||
if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){
|
if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){
|
||||||
this.parent.airjumps --;
|
this.parent.airjumps --;
|
||||||
this.finished("jump");
|
this.finished("jump");
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.update(deltaT);
|
super.update(deltaT);
|
||||||
}
|
}
|
||||||
onExit(): Record<string, any> {
|
onExit(): Record<string, any> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
||||||
|
import InputWrapper from "../../Tools/InputWrapper";
|
||||||
import { PlayerStates } from "../PlayerController";
|
import { PlayerStates } from "../PlayerController";
|
||||||
import PlayerState from "./PlayerState";
|
import PlayerState from "./PlayerState";
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,16 @@ import { PlayerStates } from "../PlayerController";
|
||||||
import InAir from "./InAir";
|
import InAir from "./InAir";
|
||||||
import PlayerState from "./PlayerState";
|
import PlayerState from "./PlayerState";
|
||||||
import { GameState } from "../../sword_enums";
|
import { GameState } from "../../sword_enums";
|
||||||
|
import Timer from "../../../Wolfie2D/Timing/Timer";
|
||||||
export default class Jump extends InAir {
|
export default class Jump extends InAir {
|
||||||
owner: AnimatedSprite;
|
owner: AnimatedSprite;
|
||||||
|
jumpTimer: Timer;
|
||||||
|
|
||||||
onEnter(options: Record<string, any>): void {
|
onEnter(options: Record<string, any>): void {
|
||||||
this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "jump", loop: false, holdReference: false});
|
this.emitter.fireEvent(GameEventType.PLAY_SOUND, {key: "jump", loop: false, holdReference: false});
|
||||||
|
this.jumpTimer = new Timer(300);
|
||||||
|
this.jumpTimer.start();
|
||||||
|
this.parent.velocity.y = -400;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,20 +38,17 @@ export default class Jump extends InAir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!this.jumpTimer.isStopped() && !this.jumpTimer.isPaused() && InputWrapper.isJumpPressed()) {
|
||||||
|
this.parent.velocity.y = -400;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jumpTimer.pause();
|
||||||
|
}
|
||||||
|
|
||||||
if(this.owner.onCeiling){
|
if(this.owner.onCeiling){
|
||||||
this.parent.velocity.y = 0;
|
this.parent.velocity.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO - testing doublejump, may have to move to InAir instead
|
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
|
||||||
if( this.parent.airjumps>0 && InputWrapper.isJumpJustPressed()){
|
|
||||||
this.parent.airjumps --;
|
|
||||||
this.finished("jump");
|
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're falling, go to the fall state
|
// If we're falling, go to the fall state
|
||||||
if(this.parent.velocity.y >= 0){
|
if(this.parent.velocity.y >= 0){
|
||||||
this.finished(PlayerStates.FALL);
|
this.finished(PlayerStates.FALL);
|
||||||
|
|
|
@ -30,7 +30,6 @@ export default class OnGround extends PlayerState {
|
||||||
// If we jump, move to the Jump state, give a burst of upwards velocity
|
// If we jump, move to the Jump state, give a burst of upwards velocity
|
||||||
if(InputWrapper.isJumpJustPressed()){
|
if(InputWrapper.isJumpJustPressed()){
|
||||||
this.finished("jump");
|
this.finished("jump");
|
||||||
this.parent.velocity.y = -600; // basically jump height
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(!this.owner.onGround && InputWrapper.getState() === GameState.GAMING){
|
else if(!this.owner.onGround && InputWrapper.getState() === GameState.GAMING){
|
||||||
|
|
|
@ -13,7 +13,7 @@ import PlayerController from "../PlayerController";
|
||||||
|
|
||||||
export default abstract class PlayerState extends State {
|
export default abstract class PlayerState extends State {
|
||||||
owner: GameNode;
|
owner: GameNode;
|
||||||
gravity: number = 1500; //TODO - can change later
|
gravity: number = 2500; //TODO - can change later
|
||||||
parent: PlayerController;
|
parent: PlayerController;
|
||||||
positionTimer: Timer;
|
positionTimer: Timer;
|
||||||
static dashTimer: Timer;
|
static dashTimer: Timer;
|
||||||
|
|
|
@ -56,6 +56,17 @@ export default class InputWrapper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static isJumpPressed(): boolean {
|
||||||
|
if (InputWrapper.gameState != GameState.GAMING) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.isPressed("jump")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not the attack key is currently pressed
|
* Returns whether or not the attack key is currently pressed
|
||||||
* @returns True if the attack key is pressed, false otherwise
|
* @returns True if the attack key is pressed, false otherwise
|
||||||
|
|
Loading…
Reference in New Issue
Block a user