The game file to import and load for this session is 5961_06_05.stencyl
.
Game Over
— Select the Dashboard tab, select Scenes, and then select Click here to create a new Scene. Leave all the settings at their default configuration and click on OK.print
block.0
(zero).We have modified the Collides with Enemies
event so that the value of the Lives
game attribute is tested after it has been decremented, and the game will switch to the Game Over
scene if the number of lives remaining is less than zero.
If the value of Lives
is greater than zero, the RestartLevel
event in the monkey's Health
behavior is triggered. However, if the value of Lives
is not greater than zero, the instruction in the otherwise
block will be executed, and this switches to the (currently blank) Game Over
scene that we have created.
If we review all the instructions in the completed Collides with Enemies
event, and write them in English, the statement will be:
When the monkey collides with an enemy, reduce the value of Lives by one and print the new value to the debug console. Then, if the value of Lives is more than zero, trigger the RestartLevel event in the monkey's Health behavior, otherwise switch to the Game Over scene.
Before continuing, we should note that the Game Over
scene has been created as a temporary measure to ensure that as we are in the process of developing the game, it's immediately clear to us (the developer) that the monkey has run out of lives. In Chapter 7, Polishing the Game, we'll be introducing a more appropriate and visually appealing game over message for our players!
The game file to import and load for this session is 5961_06_06.stencyl
.
In the section, Time for action – displaying the countdown timer on the screen, we learned how to display the value of the countdown timer on the screen during gameplay.
Using the skills that we have acquired in this chapter, try to complete the following tasks:
Score Management
behavior to display the number of lives at the upper-right corner of the screen, by adding some new instruction blocks to the Display Counter
event.Display Counter
event to Display HUD
.print Countdown
block from the Decrement Countdown
event also found in the Score Management
behavior.print Lives remaining: & Lives as text
instruction block from the Collides with Enemies
event in the Manage Player Collisions
behavior.Why did we remove the debug print …
blocks in the previous Have a go hero session? Originally, we added the debug blocks to assist us in monitoring the values of the Countdown
attribute and Lives
game attribute during the development process. Now that we have updated the game to display the required information on the screen, the debug blocks are redundant!
While it would not necessarily cause a problem to leave the debug blocks where they are, it is best practice to remove any instruction blocks that are no longer in use. Also, during development, excessive use of debug print blocks can have an impact on the performance of the game; so it's a good idea to remove them as soon as is practical.
18.216.20.236