Skip to content

Player Movement

racheljadel edited this page Oct 18, 2023 · 12 revisions

Overview

Player Movement is updated and extended to both normalise diagonal movement and implement a dodge button.

Diagonal Movement

Diagonal movement is implemented when the player presses two keys simultaneously (KeyboardPlayerInputComponent). The player will move at the same speed as the four-directional walking (Vector2Utils).

Dodge Button

The dodge button (assigned to the space bar) allows the player to move faster and further than regular walking (Vector2Utils). It has a three-second cool-down. The player can dodge up, down, left and right, which is based on the previous direction the player is moving (KeyboardPlayerInputComponent). After dodging, the player is given 0.15 seconds of immunity (PlayerActions).

Key Components

KeyboardPlayerInputComponent class:

  • diagonal: Implements the diagonal movement of the player by evaluating which keys the player is pressing and determining which direction the player wants to go. This is then scaled to the relevant vector (eg. UP).
  • triggerDodgeEvent: Implements movement of the player in the direction specified for 200 ms (using java.util.TimerTask and java.util.Timer classes) and applies temporary immunity.
  • dodge: Implements three-second cool-down using java.util.TimerTask and java.util.Timer classes.

Vector2Utils class:

  • DODGE_UP/DODGE_LEFT/DODGE_DOWN/DODGE_RIGHT: Vectors which change speed from 1 to 5, therefore allowing the player to 'dodge'.

PlayerActions class:

  • dodged: Changes immunity status of the player, implemented in triggerDodgeEvent.

Sprint 3

  • Code Smells were fixed within the KeyboardPlayerInputComponent to improve overall code quality.

Testing plan

Player Movement has been tested in accordance with the Player Movement Testing Plan

UML Diagram

Here is the UML Diagram for the Player Movement component.

Clone this wiki locally