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);
|
||||
}
|
||||
}
|
||||
//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
|
||||
}
|
||||
|
||||
super.update(deltaT);
|
||||
}
|
||||
onExit(): Record<string, any> {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import GameEvent from "../../../Wolfie2D/Events/GameEvent";
|
||||
import Sprite from "../../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||
import MathUtils from "../../../Wolfie2D/Utils/MathUtils";
|
||||
import InputWrapper from "../../Tools/InputWrapper";
|
||||
import { PlayerStates } from "../PlayerController";
|
||||
import PlayerState from "./PlayerState";
|
||||
|
||||
|
|
|
@ -8,11 +8,16 @@ import { PlayerStates } from "../PlayerController";
|
|||
import InAir from "./InAir";
|
||||
import PlayerState from "./PlayerState";
|
||||
import { GameState } from "../../sword_enums";
|
||||
import Timer from "../../../Wolfie2D/Timing/Timer";
|
||||
export default class Jump extends InAir {
|
||||
owner: AnimatedSprite;
|
||||
jumpTimer: Timer;
|
||||
|
||||
onEnter(options: Record<string, any>): void {
|
||||
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){
|
||||
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(this.parent.velocity.y >= 0){
|
||||
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(InputWrapper.isJumpJustPressed()){
|
||||
this.finished("jump");
|
||||
this.parent.velocity.y = -600; // basically jump height
|
||||
|
||||
}
|
||||
else if(!this.owner.onGround && InputWrapper.getState() === GameState.GAMING){
|
||||
|
|
|
@ -13,7 +13,7 @@ import PlayerController from "../PlayerController";
|
|||
|
||||
export default abstract class PlayerState extends State {
|
||||
owner: GameNode;
|
||||
gravity: number = 1500; //TODO - can change later
|
||||
gravity: number = 2500; //TODO - can change later
|
||||
parent: PlayerController;
|
||||
positionTimer: Timer;
|
||||
static dashTimer: Timer;
|
||||
|
|
|
@ -56,6 +56,17 @@ export default class InputWrapper {
|
|||
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 True if the attack key is pressed, false otherwise
|
||||
|
|
Loading…
Reference in New Issue
Block a user