Skip to content

Player Movement

racheljadel edited this page Aug 30, 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 one second of immunity, however, they are also unable to attack during this time period (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 is wanting 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.
Clone this wiki locally