Skip to content

Score System

sh4453 edited this page Sep 14, 2021 · 12 revisions

Purpose

Scoring systems are a key component of gameplay. They provide a mechanism that rewards players with point values whenever a task is accomplished in the game. This incentive to achieve the highest score encourages players to repetitively complete the game without losing too much health in the shortest time possible. Scoring systems considerably influence the satisfaction of players during gameplay and providing an incentive to challenge themselves.

Functionality

The score system utilises time and the health of the player. The player will initially start with 1000 points and their points will decrease by one every second. If the player loses health they also lose points by the health lost multiplied by 7.

The class is first initialised when called in spawnPlayer() in ForestGameArea.java and added to the player entities compononents. The constructor for ScoreComponent is:

public ScoreComponent() {
    //health = combatStats.getHealth();
    score = 1000;
    timerTick = 1;
    timer = TimeUtils.nanoTime();
}

The score is what the players initial score where, timerTick is the lose in points every second and the timer is a timer that runs in nanoSeconds. For the score to be updated the updateScore() function is run

public void updateScore() {
    if (TimeUtils.timeSinceNanos(timer) > 1000000000) {
        timer = TimeUtils.nanoTime();
        setScore(score - timerTick);
    }
    int healthDifference = 0;
    int currentHealth = combatStats.getHealth();
    if (currentHealth != health) {
        healthDifference = currentHealth - health;
        health = combatStats.getHealth();
    }
    int newScore = getScore() + (7 * healthDifference)
    setScore(newScore);
}

This function will check against the timer and see if at least one second has passed for the timerTick to reduce the score. It also checks if the player has lost any health and to reduce the score respective to the amount of health lost. It then calls the function setScore() which sets the score saved to the component to the newScore.

public void setScore(int score) {
    this.score = score;
    if (entity != null) {
        entity.getEvents().trigger("updateScore", this.score);
    }
}

Above is the setScore() function that triggers an Event "updateScore" which is in the PlayerStatsDisplay() and updates the components score to a new score. In addActor() in PlayerStatsDisplay() a new table and label is created for the score called scoreTabel and scoreLabel respectivelly. and a new listener is create() being 'entity.getEvents().addListener("updateScore", this::updateScoreUI);`

Below is the updateScoreUI() which simply sets the score to a given value. public void updateScoreUI(int score) { CharSequence text = String.format("Score: %d", score); scoreLabel.setText(text); }

To display the score on the player's win and lose pop-up menus their respective PlayerDisplays() it also required the designs to be updated to allow more information to be displayed on these screens. For the PlayerWinDisplay() the new constructor is now

public PlayerWinDisplay(PopupUIHandler handler, Entity player) {
    this.handler = handler;
    this.score = player.getComponent(ScoreComponent.class).getScore();
    this.progress = Math.round(player.getComponent(ProgressComponent.class).getProgress());
    this.steps =  Math.round(player.getPosition().x * 10);
    this.health = player.getComponent(CombatStatsComponent.class).getHealth();
}

This is setting values that will be displayed on the menu by accessing the player entity's components. This was done to allow future implementation for other components to be potentially displayed. AddActors() has been updated to now include 4 new tables and labels one for each of the stats that will be displayed, for the player's score it appears.

public void addActors() {
    Table scoreTable = new Table();
    scoreTable.top().left();
    scoreTable.setFillParent(true);
    scoreTable.padTop(350f).padLeft(350f);
    CharSequence scoreText = String.format("SCORE: %d", score);
    Label scoreLabel = new Label(scoreText, skin, "large");
    scoreTable.add(scoreLabel);
    stage.addActor(scoreTable);
}

This is also done for stats such as distance in steps, remaining health and completion percentage of the level. These pop-up menus had to be redesigned using new design templates such as seen below as the previous design was not suitable for more information to be added to it.

UML Diagram

Below is a simple UML diagram of the ScoreComponent to display it on the MainGameSreen

Interfaces

The score will be visible to the player at numerous locations on the screen. Custom loss screens were created to display and notify the player of the various loss conditions caused by different enemies and obstacles. Some information about the enemy obstacle will also be presented to the player, along with their score and button options to redirect to the main menu screen or replay from a checkpoint. The design of the interface was designed in an attempt to match some previously designed Loss & Win Menu Screens.

Interfaces have a blank area to insert text within the game, which will include the score and possibly player stats (eg. times jumped, number of power-ups used, number of lives collected, etc.)

Example Loss Screen Robot Death Ufo Death Asteroid Death
example interface robotDeath ufoDeath asteroidDeath
Example Win Screen
win screen example win screen

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