Sometimes, you don't want a script to start working right from the start of the game. For such cases, you can trigger a script by sending a message, instead of just starting it when the <green flag> button is pressed. This way, the script will stay dormant and inactive until it receives the right message. You can actually compare this to someone yelling a certain order that the script has to respond to. In this section, we will postpone the appearance of the boss monster until certain game conditions are met.
Messages are part of the Events category. Let's go there and see what we have to work with. Near the bottom of the list are three message blocks; one starting block (with the curved top) that can receive a message, and two broadcasters immediately below that can shout a message to all the scripts.
We will use these messages to differentiate between the two states of the game. The player can either fight waves of enemies or the boss. Depending on the case, certain scripts have to be made active/inactive:
boss
. This message should summon the boss's state in the game.waves
.To make use of these broadcasts, someone (or something) has to listen to them. The important sprites that need to respond to the messages are the Starfish enemies and the boss, which are yet to be created:
To stop and remove the Starfish enemies when the boss phase of the game is reached, we need to add a third script as follows:
When we test the game again, we won't notice any difference. Starting the game will still spawn enemies wave after wave, provided we set up everything properly. If we can survive until the timer reaches 90 seconds, we will see a change. At this point, the boss message will be broadcast. The enemies will respond by disappearing.
The diver can still move about, and the background will keep scrolling. Other than this, nothing exciting happens. We will change that in the rest of this project.
3.15.22.160