-
Notifications
You must be signed in to change notification settings - Fork 0
Player Sprinting Functionality
A sprint feature is a mechanic in the game. Whilst it is easy to use, the timing of the sprint feature might become crucial when the game gets more difficult, as sprint is a limited resource.
While in game, if the left-shift key is pressed, the player's movement will be increased and the sprint gauge (bellow the health value) will decrease. If the player is standing still and decides to sprint, nothing will happen and as long as the left-shit key is held down, the sprint gauge will decrease. Currently, the sprint gauge cannot be regenerated. However, in the future this might be possible when the player collects a power up, etc.
The SprintComponent
class was made, and was added to the PlayerFactory
class:
.addComponent(new SprintComponent(100));
Within the KeyboardPlayerInputComponent
class, logic for a sprint event was added:
private void triggerSprintEvent(boolean sprinting) {
if (entity.getComponent(SprintComponent.class).getSprint() == 0){
return;
}
if (walkDirection.epsilonEquals(Vector2.Zero)) {
entity.getEvents().trigger("walkStop");
} else {
entity.getEvents().trigger("sprint", walkDirection, sprinting);
}
}
Currently, sprint works by adding another movement vector in whichever way the player is moving, this can most definitely be improved by scaling the current movement vector, but that caused issues when the player would suddenly change direction mid-sprint, so it was implemented as so:
void sprint(Vector2 direction, boolean sprinting){
if (direction.x > 0){
//if the player is moving right
if (sprinting){
//if sprint was called on keyDown, increase speed
this.walkDirection.add(Vector2Utils.RIGHT);
} else {
//player has stopped sprinting, subtract speed
this.walkDirection.sub(Vector2Utils.RIGHT);
}
}
if (direction.x < 0){
//if the player is moving left
if (sprinting){
this.walkDirection.add(Vector2Utils.LEFT);
} else {
this.walkDirection.sub(Vector2Utils.LEFT);
}
}
}
Another issue that caused problems was when the player would hit the sprint key first, and then start moving. This was fixed (however there are probably better solutions) by checking this at every keyDown / keyUp event. For example:
case Keys.A:
if (entity.getComponent(SprintComponent.class).getSprint() > 0 && isSprinting){
//if sprint is active before moving, add twice the speed
walkDirection.add(Vector2Utils.LEFT);
walkDirection.add(Vector2Utils.LEFT);
triggerWalkEvent();
return true;
}
A timer was used to deplete the sprint amount at a certain rate (as long as the player is sprinting):
public Timer timer = new Timer();
public Timer.Task removeSprint = new Timer.Task() {
@Override
public void run() {
entity.getComponent(SprintComponent.class).removeSprint(1);
if (entity.getComponent(SprintComponent.class).getSprint() == 0){
//if sprint has fully depleted
if (walkDirection.x > 1){
walkDirection.sub(Vector2Utils.RIGHT);
}
if (walkDirection.x < -1){
walkDirection.sub(Vector2Utils.LEFT);
}
timer.stop();
isSprinting = false;
}
}
};
Finally, the sprint amount was added on to the UI, similar to the way the health was added:
int sprint = entity.getComponent(SprintComponent.class).getSprint();
CharSequence sprintText = String.format("Sprint: %d", sprint);
sprintLabel = new Label(sprintText, skin, "large");
- Player UI
- Popup Menus
- Obstacles
- Boss Enemies
- Progress Tracker
- Checkpoint Design and Functionality
- Score System
- Lives System
- Game Background
- Multiple game-level
- Visual Improvements
- Tutorial Level
- Character Design and Animations
- Character Damage Animations
- Player Animation Functionalities
- Player and Serpent Portal Transition
- Pop-up Menus
- Obstacles
- Lives & Score User Testing
- Buffs & Debuffs
- Buffs & Debuffs redesign
- Obstacle Animation
- Background Design
- Level 2 Background Appearance
- Enemy Monster User Testing
- Level 1 Floor Terrain Testing
- Introduction Screens User Testing
- Character Movement Interviews & User Testing
- Sound user testing
- Level 2 Obstacles and enemy
- Story, Loading, Level 4 and Win Condition Sound Design User Testing
- Giant Bug and Purple Squid animation user testing
- General Gameplay and Tutorial Level User Testing
- Level 4 Terrain User Testing
- Game Outro User Testing