This blog post was designed as a follow up to the Level Creation post.
Just having the levels designed and built is not enough. In order for each level to function as intended they need to record the users deaths, and the amount of time it has taken them to play.
The first thing that I added to each level was a behaviour that reset the level and added a death to a global variable if the user was to die.
The screenshot shows the Death behaviour that I created and attached to each level. Essentially if the users Actor makes contact with any other Actor they have made contact with an ‘enemy’.
When the user dies they script automatically takes the number of existing deaths and adds one to the number resulting in an increase of one death being recorded on the ‘TimesFried’ global variable.
Once this has been done the scene crossfades and reloads the scene.
Proceeding to the next Level
In the game the user has to reach the right-hand side of the screen in order to proceed to the next level. During map creation I placed an invisible region down the entire right side of the screen so that on contact the user would be transported to the next level.
This behaviour detects when the users Actor enters a specified region. On entry the behaviour will automatically crossfade the scene from the existing onto the scene that is specified to load next.
In order to record the time that the user took to complete each level another behaviour was required.
This behaviour is always running, so as soon as it finishes running it runs again. Essentially it waits one second and then adds one second to the global variable ‘Timer’. This allow the same timer to be shared by all levels in order to calculate how long it has taken the user to complete the game.
It is important to wipe any old user data before letting them start a new game. In order to ensure that they do not keep any old deaths or add onto the old timers the system stats are all reset at the start of the first level.
This behaviour simply takes each of the three global variables and resets them back to ‘0’ ensuring a fair and consistent user experience.
All of these simple behaviours are essential to ensuring that the game runs properly and can perform the necessary functions. Although they are all relatively simple without them the game simply could not operate.