Skip to content

Player Rolling Functionality

default-jamc edited this page Oct 4, 2021 · 2 revisions

Usage

While landed, the player can hit Q or E to roll left or right, respectively.

Implementation

The roll functionality makes use of the RollComponent class, and works closely with the KeyboardPlayerInputComponent and PlayerActions classes.

Controlling Variables

The main variables which control the characteristics of the roll mechanism is the RollComponents ROLL_LENGTH, ROLL_TIME and ROLL_COOL_DOWN.

  • ROLL_LENGTH: the 'length' of the players roll. Increasing this variable increases the players speed throughout the roll.
  • ROLL_TIME: the duration of the players roll. Increasing this variable increases how long the player will move for.
  • ROLL_COOL_DOWN: the cool-down that the player must wait for before they are able to roll again. Increasing this variable increases the amount of time the player must wait between rolls.

Currently, rolling does not drain Sprint nor any sort of Stamina.

Roll Sequence

Starting the roll

When the player hits Q or E, if the player is not mid-air, the RollComponent's handleRolling function is called.

public void handleRolling(Vector2 direction) {
    /* Rudimentary set-up code */
    ...
    
    move(direction.cpy().scl(ROLL_LENGTH));

    animateRoll();
}

The move function calls upon the PlayerActions walk function.

Ending the roll

Updated Implementation

After the addition of dynamic map generation as part of the new terrain, it was found that using offCollision as a mechanism to determine whether or not the player fell off an object was not suitable. The previous implementation was amended to automatically (always) reapply gravity to the player as soon as the roll ends, regardless of whether they fell off something or not. The new handleStopRolling function is as follows:

private void handleStopRolling() {
    /* Rudimentary set-down code */
    ...
    stopRollAnimation();

    entity.getEvents().trigger("walk", Vector2Utils.DOWN);
    ...
}

Initial Implementation

After the ROLL_TIME has elapsed, the RollComponents handleStopRolling function is called.

private void handleStopRolling() {
    /* Rudimentary set-down code */
    ...

    handleCheckingFallRequired();
}

Additional actions must be taken if the player rolled off something. Since the roll has a set duration, there is no keyUp functionality for it (ie, nothing happens when the player releases the Q or E key, dissimilar to A and D in the walk functionality). Due to this, the player must manually have gravity re-applied to bring them back to the ground.

private void handleCheckingFallRequired() {
    if (the player rolled off something) {
        this.falling = true;
        move(Vector2Utils.Down);
    }
}

Whether or not the player rolled off something is determined using offCollisions. If the player stopped colliding with something while they were rolling, then they have fallen off of a physics object.

Once the player reaches the ground, they are able to roll again once the cool-down period ends.

Cool-down period

After the player has rolled, the lastRollEnded variable is set, which is a double containing the absolute time at which the players roll will end. Once this time is hit, the rollOnCoolDown variable is set to false, and the player will be able to roll again.

Table of Contents

Home

Introduction

Main Menu

Main Game Screen

Gameplay

Player Movement

Character Animations

Enemy Monster Design and Animations

Game basic functionalities

User Testing

GitHub Wiki Tutorial

Game Engine

Getting Started

Documentation

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally