Skip to content

Player Input and Controls

martinrbaer edited this page Aug 30, 2021 · 8 revisions

Player Input and Controls

When the player has pressed the correct controls, the entities will trigger an event depending on the control passed in. The set of controls currently available are W, A, S, D for basic player movement, LEFT_SHIFT for sprint and CAPS_LOCK for dashing (to be changed).

Pressing any of these keys will cause an event to be triggered, W, A, S, D will trigger a walk event, LEFT_SHIFT will update the speed multiplier and CAPS_LOCK triggers the dash event.

Player Actions

This class handles what inputs do for anything related to the character. Each event needs to be added to the EventListener list and some of the methods included in this class are:

  • walk: sets the direction the player is walking in and sets moving to true
  • stopWalking: sets the direction the player is walking in to zero and sets moving to false
  • attack: currently plays a sound but this is to be changed
  • dash: sets the direction the player is walking in and sets moving to true

Keyboard Player Input Component

This class handles the keyboard inputs from the player. It will check for key presses and releases and will call methods accordingly. The keys that are currently being checked for are:

  • W: moves the character up
  • A: moves the character left
  • S: moves the character down
  • D: moves the character right
  • LEFT_SHIFT: changes the speed multiplier
  • CAPS_LOCK: the character dashes in the direction currently being moved in
  • MOUSE_1 or SPACE: calls an attack *
  • *If MOUSE_1 the direction of the attack is dependant on the quadrant that the mouse is clicked in. If SPACE the direction of the attack is dependant on the direction that the player last moved.

Private Methods:

  • triggerWalkEvent: calculates the vector distances the player is to move in and then triggers the walk event
  • triggerDashEvent: calculates the vector distances the player is to dash in and then triggers the dash event
  • calculateDistance: calculates the vector distances depending on diagonal movement and scale

calculateDistance

The base game engine did not have anything to handle diagonal movement so a private helper method calculateDistance has been made to check if the player is moving diagonally as well as multiply the vectors by a scale that has been passed in.

To Implement

More abilities are to be added such as basic attacking and other damaging abilities. These abilities would need a cost or a cooldown for usage. Attacks may require mouse input which will be handled by a different class depending on how the character will be controlled.

Using CAPS_LOCK and SHIFT can feel awkward to switch between so testing of a mechanic that causes the player to only sprint after a dash will be trialed and tested to determine if it makes the controls feel more coherent.

At times the dashing ability can feel jerky and does the frames cannot keep up with it. Changing the dash so the speed will gradually scale to max speed has been considered and will be tested to see if this will help.

Class Relations Diagram

The association between the PlayerActions, PlayerAnimations and the Player class is abstracted with the used of a physics class for movement and an animator class for animation.

KeyboardPlayerInput, PlayerActions and PlayerAnimations are all components that the entity contains. The KeyboardPlayerInput will trigger events that will call methods within PlayerActions and PlayerAnimations.

image

Table of Contents

Home

Design Document

Design Document

Design Document

Game Engine

Getting Started

Entities and Components

Item Drops from Entities

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Map Generation

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally