Adding a test script

Before we dive into the excitement of creating the boss enemy, let's first do something smart and create a script that helps us to test the boss that we create.

Prepare for lift off

As you may have noticed while testing the game, waiting 90 seconds for the boss to appear is a rather long time. We could just decrease the wait time in the script, but that has a few drawbacks.

It would be more difficult to test the wave phase of the game, since the timer runs for such a short time.

We run the risk of forgetting to change the timer before finally publishing the game.

A better option is to create a separate temporary script that we can throw away when we have finished the game without any risk to all our hard work.

Engage thrusters

We will add this script to the Stage sprite. This is often the best place for these kinds of control scripts.

When a certain button is pressed, we will change the ordinary flow of things, as follows:

  1. Start a new script with a when <b> key pressed block. We can use any available key. In this case, "b" stands for "boss", as a handy reminder about what we are trying to do.
  2. We set the three score values (using set () to ()). This is similar to the when <green flag> clicked script next to it.
  3. Instead of supplying a fixed number, we will use pick a random number between () and () and fill in the values 1 and 30 respectively. This way, we fake having scored some points during the game, so we can see the effects of the upgraded spear on the boss.
  4. Then we use broadcast <boss> to start the boss phase immediately.

The final script will look like the following screenshot:

Engage thrusters

This is all that is absolutely necessary for this script. As you can see, the timer is still running and will eventually reach 90. This would cause the boss message to be called again. We don't want that as it could cause strange results. So, we will take a few precautions to prevent the timer from ever reaching 90.

Stopping the timer altogether would be a great option, but unfortunately Scratch doesn't allow that. The precautions to be taken are as follows:

  1. We attach a forever loop after the broadcast block.
  2. Inside the loop, we place an if () then block.
  3. The condition will check whether timer > () with value 80.
  4. If this is the case, we sneakily use reset timer so that it will start over from 0.
    Engage thrusters

Objective complete – mini debriefing

After we start a new game, we can press the B key to immediately jump to the battle against the boss. We make sure the spear has some random upgrades so that we can see the effect. We also make sure the timer that's set for the usual game flow doesn't bother us.

We can now quickly skip to and test the boss fight without first having to play through a wave of enemies.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.188.138