B - InGame systems
+ Behaviors used : None; Plugins used : System, Sprite, Keyboard, Text, Textbox, Array, Local Storage, Audio, Function, TiledBackground.
What I call "InGame systems" here are systems that will work around and in the game's logic.
It encompasses: the pausing system, the wave system, the score system and the audio system.
1 - Pausing system
The pausing system is not in a group. It's a "simple" top event, when the player presses "P", the process of pausing/unpausing kicks in.
Checking that the "Asteroid" count is over 0 helps making sure that the game has already started (and that we're not just expecting the player to press return on start or between waves).
More on this in the next chapter (Wave system).
Just notice that the conditions surrounding the player's input (the triggered condition "On key pressed") allow to determine if the game is in the correct circumstances to execute the player's intent (here, is it a viable time in the game to pause ?).
Pausing/unpausing is passing between two different states.
A simple way to pause a game is to set the "timescale" system expression value to 0. (like in event 38)
Any behavior, plugin, formula using the system expression dt (see the Delta-time and frame-rate independence tutorial) will then be paused in its execution as long as "timescale" is equal to 0.
Event 37 checks if the game is currently paused (if so, it modifies the values so that the game goes back into "playing" mode).
Event 38 will execute only if the previous event (is the game paused ? event 37) hasn't.
It then means that the game is playing, and that currently the player wants to pause it.
In this current project "timescale" does the job as mostly built-in behaviors and plugins are used.
The "regular" "timescale" value is 1.0. At 1.0 everything executes at "normal" speed. This is the way to unpause the game.
So "timescale" stops the execution/animations/movements of the game's object, but the player can still interact, still can input commands to the game.
So Event 38, we deactivate the group "PlayerMovement" (remember, it is the group in which we have put all our events concerning the player's control of the ship), shutting down the capacity for the player to input commands, other than the one currently expected and treated outside of this group: "Press "Return"".
Event 37 (unpausing) of course the group is activated, otherwise the player couldn't play the game as intended.
It's also nice to display feedback to the player, and a "Pausing" state needs to be clearly understood or the player might think the game has bugged.
As I implemented the pausing system quite late in my development (it's part of the reason why it is the last in the event-sheet and not in a group), I chose to reuse another GUI element that was already there.
In the layout game, you can see the text object "txtWave" which is a simple text object I use to give feedback to the player in between the waves (more on this in the "Wave System").
So in event 38 (pausing the game) we set "txtWave" to be visible, and set its text so it notifies the player that the game is paused and that pressing "P" again will unpause.
In event 37 (unpausing the game) we only need to set it invisible. Its text will be modified by either the wave system or the next pausing anyway.
The reuse here works because this object has about the same function in the Wave System (just being switched between visible and invisible and displaying some text in between the waves) and is correctly positioned for the job.
As I said, I implemented the Pausing system pretty late in my development but I thought it was better to begin with it in the tutorial.
It's a quick 3 events (1 top, 2 sub events) function that is pretty used/useful.
Be aware though that it strongly depends on the way you implemented your game so far.
As I had "custom inputs", in a group of events, using only timescale = 0 was not enough.
When you try to do your own pausing process, make sure that it covers all the game as you made it.
2 - Wave system
The game points list in the first pages stated:
Wave system
..° Each wave "spawns" a limited numbers of asteroids.
..° Once every asteroids have been destroyed, the wave is ended, we wait for an input (press return) from the player and we start the next wave.
..° The background picture is changed every wave.
This is where all the previous code and the setting of the "Asteroid" object type comes in play.
Every "Asteroid" instances will have the same mechanism/game behavior. They will all react the same way to the events.
And "all" that there is to do is to spawn a few of those object at the start of the wave, and the game will play as expected.
The wave system is in the group "WaveSystem" in "esGame" (event 25) and makes use of the global variable "Wave" (defined in the same event sheet).
The event 26 is actually the event that checks if the wave has ended.
Event 27 is useless as long as the wave hasn't ended.
The conditions to check if the wave has ended are :
° Make sure that all the "Asteroid" have been destroyed
° Make sure that we are not at the start of the game, before the very first wave
° Make sure that "Player" is still alive
° Make sure that the game is not paused
That's exactly what the 4 conditions of the event 26 do.
+ Breaking down the code