Dash - UQdeco2800/2022-studio-2 GitHub Wiki
Dash Code
Dash Modified Movement
The dashing movement is modified by the following code. We can see that this involves basic vector addition of the movement direction and the dash direction, however involves DASH_MOVEMENT_RESTRICTION constant (should always be between 0f and 1f) to reduce the side to side movement of the player during the dash. This movement is called in getModifiedMovement and can be combined with other skills which modify player movement.
Vector2 modifiedMovementVector = baseMovement;
if (isDashing()) {
Vector2 dashVelocity = dashDirection.cpy().scl(DASH_SPEED);
Vector2 reducedMovement = new Vector2(modifiedMovementVector.x * DASH_MOVEMENT_RESTRICTION,
modifiedMovementVector.y * DASH_MOVEMENT_RESTRICTION);
modifiedMovementVector = addVectors(reducedMovement, dashVelocity);
}
Checking for Dash Player Movement
This allows for external functions to check the skill state of the dash. Please note: this is only valid assuming the PlayerSkillComponent.update() has been called as this checks for the time stamps of the skill state.
/**
* Checks if the player is in the dash skill state
* @return true - if the player is dashing
* false - otherwise
*/
public boolean isDashing() {
return this.dashing;
}
Calling the Dash Skill
This function sets all the relevant variables for the skill state. This function was specifically designed to not break functionality on multiple calls even when already in the dash state (this was done using time stamps of the dash skill end, so if called again the dash skill state is just updated to a later time finish). Here we can also see that the dash invokes a period of invulnerability from enemy attacks.
/**
* The functional start of the dash.
* Should be called when player actions component registers dash event.
* @param moveDirection the direction of the players movement at the start of the dash event.
*/
public void startDash(Vector2 moveDirection) {
this.dashDirection = moveDirection;
this.dashing = true;
long dashStart = System.currentTimeMillis();
this.dashEnd = dashStart + DASH_LENGTH;
setInvulnerable(DASH_LENGTH);
}