Just one more thing to do to finish the game. At the moment, the enemies can win the game by destroying the base. But the player can't really win the game. There's no clear end state to kill all the enemies. To finish the game, we will determine fixed winning and losing conditions and add a game screen to clearly tell the player whether they have won or lost the game.
Let's create the screen graphic first by following the given steps:
YOU WIN!
in the center of the rectangle.GAME OVER
.To show the game screen at the right moment and to display the proper costume, we will use a script as shown in the following steps:
game over
.Scripting for the win condition is a bit more work. When does the player win the game? When all the enemies have been killed or have entered the base while the base has not yet been destroyed. The last part of that condition is already taken care of because the scripts we have just written will put the game in the game over state as soon as the base is destroyed. If we haven't reached the game over state yet, the base must still be "alive".
So we only have to take care of counting the enemies and check whether we have reached the total yet.
First, count the total number of enemies that are spawned during the game. If you've used the numbers mentioned earlier, there should be 35 enemy clones moving through the game. Remember that number. The following are the steps to count the number of enemies:
enemies
.0
block at the start of the game screen <green flag> script.35
.1
block in both clone scripts, just before a clone is destroyed. This counts all the enemies as they are killed or when they have reached the base.Test the game to see whether you performed all the steps correctly. Temporarily show the enemies variable by checking the boxes to see if the counting works. Try killing all the enemies to get to the win condition. Also, test to see whether the enemies destroying the base will get the game to the game-over condition.
18.226.177.86