feat: jump height depend on pressing time

This commit is contained in:
Renge 2022-05-07 22:18:09 -04:00
parent a906d19842
commit bc347270a6
6 changed files with 25 additions and 16 deletions

View File

@ -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> {

View File

@ -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";

View File

@ -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;
}
@ -34,19 +39,16 @@ 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);

View File

@ -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){

View File

@ -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;

View File

@ -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