Skip to content

Level System Overview

Michael Kidd edited this page Sep 7, 2024 · 25 revisions

Table of Contents

Introduction

Coding Overview

   Summary

      Rationale

      Implementation Summary

      Usage Summary

Introduction

The Level System is what defines the number of customers spawning depending on the level, and how 'difficult' each level should be - with 'difficulty' being defined as the number of interactions required to successfully get through the day, meaning levels with a 'higher difficulty' require more interactions in order for the player to get complete the day.

The back-end of the Level System is comprised of two parts, a LevelService and a LevelComponent. The LevelService acts as a way of globally handling and tracking events related to levels - mainly for triggering them. The LevelComponent acts as sort of spawn controller which is added to an Entity in order to control when and what customers are spawned on screen.

Coding Overview

NOTE: The spawning stuff is temporary for now, until proper customer spawning code is provided

Summary

The Level System as a whole consists of two separate classes, LevelService and LevelComponent. The LevelService acts as a globally accessible service which can be registered to the ServiceLocator and allows for the control - triggering a levels spawning pattern and other related events - and tracking of various level related variables - e.g. what the current level is. This is done by having LevelService store an EventHandler as well as several private variables and methods. The two most important events that the EventHandler has listeners for is the startLevel and startSpawning events. The startLevel event calls the levelControl() method in the registered LevelService object. When levelControl() is called, it calculates what the spawn cap of the level should be, and then triggers the startSpawning event, which is parsed the spawn cap variable. The startSpawning event is related heavily to the LevelComponent class.

The LevelComponent when added to an Entity makes it (the Entity) act as a spawn controller, controlling when customers spawn on screen and which customer spawns on screen. When the startSpawning event is triggered, the method initSpawning() is called. When called, this method ensures that all private variables in the LevelComponent object are set to default values and then calls a method called toggleNowSpawning(). When this method is called, a check present in the update() method now passes, which then allows for customers to be spawned. When customer spawning is allowed, a check is done to see if it has been three seconds since the last customer spawned, if another customer can be spawned (the spawn cap has not been reached yet) and if another customer can join the line up. If all of these conditions are true, then another customer is spawned. When the spawn cap is reached, then toggleNowSpawning() is called again, preventing anymore customer spawning from occurring.

Rationale

In order to make a spawn controller, it was decided the best course of action would be to create a class that extends Component, as the update() method could be overwritten, which, when an instance of LevelComponent is added to an Entity, allows for easy asynchronous checks due to the EntityService. To be completely honest, I also had no other ideas of what possibly I could do and I had no idea about scheduling events. Oh well. Additionally, using a Component allowed for a factory design pattern to be used to instantiate a "spawning controller Entity."

Creating a new type of service for use with the ServiceLocator was done because it is a very robust and preexisting method of global access, with several other services already being implemented for similar purposes.

Implementation Summary

Below is the constructor for the LevelService, which initialise some private variables, and most importantly registers some listeners.

image

The levelControl() method called by the startLevel event currently takes one parameter. All it does for now is limit the number of customers that spawn.

image

This is in the MainGameScreen class, at the bottom of the constructor. The first two statements become more relevant in later photos.

image

This is from the LevelComponent class. The event startSpawning, if you remember, is triggered in LevelService by levelControl()

image

This is what the event startSpawning calls. This method basically just ensures that all private variables are reset, but most importantly, enabled spawning through the toggleNowSpawning() method.

image

Speaking of, here is the toggleNowSpawning() method

image

Now the reason why I use a Component in the first place is because the Entity class has a very nice method which is update() for asynchronous code which can be called constantly (I didn't know about scheduledEvents)

image

And finally, in the create() method in ForestGameArea, the event spawnCustomer is registered (the event triggered during the hijacked update() method).

image

And this is what the spawnCustomer() method looks like, again, in the ForestGameArea class (it was conveniently already here)

image

Usage Summary

Accessing LevelService

In order to access the LevelService then ServiceLocator.getLevelService(); must be used, which returns the LevelService.

Example:

LevelService levelService = ServiceLocator.getLevelService();

Accessing the EventHandler

In order to access the EventHandler, use .getEvents();, which returns the EventHandler stored in LevelService. When accessed, the EventHandler has the standard methods, most importantly, trigger() and addListener().

Example:

EventHandler eventHandler = levelService.getEvents();
eventHandler.addListener("exampleEvent", this::exampleMethod);
eventHandler.trigger("exampleEvent");

Table of Contents

Home

Team Design Document

Game Features

Inventory System
Scoring System
Food Recipes
Level System
Player Actions
Ordering System
Stations
Items
Map Design
Customers
Pause Menu
Upgrades
End of Day Display
Day Night Cycle
Moral System
Debug Terminal
Game Interactions Tutorial
Backstory Cutscenes

Game

Getting Started

Entities and Components

World Backstory

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Map Design

Test Plans

Sensor Component

Customer Sensor Component

Interaction Component

Inventory Component

Inventory Display

Station Meal Component

Station Progress Display

Keyboard Input Component

Fire Extinguisher Handler Component

Score System

HoverBox Component

MainGameActions Create Docket Triggers

End Day Display Component

Cutscene Area

Docket

Docket Line Display

Docket Meal Display

Main Game Order Button Display

Order Actions

Recipe

Ticket Details Component

BackstoryCutscene Test Plan

BackstoryCutsceneDisplay Test Plan

Test Plan for Tutorial

Keybinds

Keybinds Test Plan

Test Plan for MainGameOrderTicketDisplay

Test Plan for MainGameOrderBtnDisplay

Test Plan for Docket

Test Plan for DocketLineDisplay

Test Plan for OrderActions

Ticket Details

Test plan for RandomComboService

Test plan for LoanUpgrade

Test plan for UpgradesDisplay

Test plan for RageUpgrade

Test plan for SpeedBoostUpgrade

Test plan for DancePartyUpgrade

Test plan for ExtortionUpgrade

Troubleshooting

MacOS Setup Guide

Clone this wiki locally