-
Notifications
You must be signed in to change notification settings - Fork 2
Level System Overview
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.
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.
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.
Below is the constructor for the LevelService, which initialise some private variables, and most importantly registers some listeners.
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.
This is in the MainGameScreen
class, at the bottom of the constructor. The first two statements become more relevant in later photos.
This is from the LevelComponent
class. The event startSpawning
, if you remember, is triggered in LevelService
by levelControl()
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.
Speaking of, here is the toggleNowSpawning()
method
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
)
And finally, in the create()
method in ForestGameArea
, the event spawnCustomer
is registered (the event triggered during the hijacked update()
method).
And this is what the spawnCustomer()
method looks like, again, in the ForestGameArea
class (it was conveniently already here)
In order to access the LevelService
then ServiceLocator.getLevelService();
must be used, which returns the LevelService
.
Example:
LevelService levelService = ServiceLocator.getLevelService();
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");
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
Entities and Components
Input Handling
Game Screens and Areas
Fire Extinguisher Handler Component
MainGameActions Create Docket Triggers
Main Game Order Button Display
BackstoryCutsceneDisplay Test Plan
Test Plan for MainGameOrderTicketDisplay
Test Plan for MainGameOrderBtnDisplay
Test Plan for DocketLineDisplay
Test plan for RandomComboService
Test plan for SpeedBoostUpgrade
Test plan for DancePartyUpgrade