Creating the boss

With all the preparations out of the way, we can start working on the boss fight. We will first create a new sprite to work with. In the following paragraphs, we will add functionality to this sprite to make it a worthy boss.

Engage thrusters

We only need to add one new sprite for the boss. Let's choose an interesting creature that's obviously different from the starfish we used already. It should still fit the watery theme of this game.

Gobo, the new Scratch mascot, is a good candidate. He looks somewhat like a sea creature and is very recognizable:

  1. Click to choose a sprite from library icon.
  2. Select the Fantasy category to narrow down the list.
  3. Gobo can now be easily found and selected. We click on the sprite and then on the OK button.

The following screenshot illustrates the preceding process:

Engage thrusters

This adds the sprite to the stage. We won't make any visual changes to it. However, we will add some scripts to it to work on the way it behaves:

Engage thrusters

To control the behavior of the script, we will create a few variables.

Engage thrusters

All these variables are local to a single sprite, so we have to make the proper settings.

  1. We need a few different variables. These variables are set to for this sprite only.
    • hitCount: This variable determines the number of hits the boss can take before being defeated.
    • speed: This variable determines how fast the boss will move across the screen.
    • turnStep: This variable determines how many degrees the boss will turn between each step. This will be used in one of the attack patterns that we write.
    Engage thrusters
  2. We also create a list to hold the broadcast messages for the attack patterns.
  3. We name the list attack patterns.
  4. We fill the list with the following three items/words:
    • pattern1
    • pattern2
    • pattern3
    Engage thrusters

With these variables created, we can write a script that sets up all the required values at the start of the game.

  1. We will start this script with a when I receive <waves> message block, because this message triggers the game to start after changes have been made in the previous project.
  2. Next, we hide the sprite (using hide).
  3. We also use set size to () % with value 40, so it isn't too big compared to everything else.
  4. Then we use set hitCount to () using value 0.
  5. We use set speed to () with value 6.
  6. Then we use set turnStep to () with value 5.
  7. We make the sprite face left with point in direction () using value -90.
  8. To conclude the script, we move it to its starting point with go to x: () y: (), filling in values 200 and 0 respectively.

The finished script looks like the following screenshot:

Engage thrusters

The boss sprite will remain in this static, invisible state until the boss event is triggered with the boss message. So let's create the following script to trigger the boss' behavior:

  1. We start with when I receive <boss>.
  2. The next thing we do is show the boss sprite (using show). We already set up everything else.
  3. Then we pick an attack pattern. We use a message to trigger the correct script to do this.
  4. Since the pattern has to be a random choice between three options, we create an assembled script block based on the attack pattern list and a random number.
  5. In any case, we use broadcast () to send a message.
  6. The empty space should be filled with item () of <attack patterns>.
  7. To pick the item from the list, we use pick random () to (); fill in the values 1 and 3 respectively.
    Engage thrusters
  8. This will trigger the first random attack pattern to start.
  9. We then start a condition loop to check whether the boss has been defeated yet.
  10. Attach a repeat until () block.
  11. The condition to check for will be if hitCount = () with value 50. (This number can be changed to make it easier/harder to defeat the boss.)
  12. Inside the loop, while the enemy hasn't been defeated yet, we will check if it touches the spear sprite using touching spear. Technically, this will be a clone of the spear sprite but for the script that doesn't make a difference.
  13. When an enemy is hit by a spear sprite, we will use change <hitCount> by () with value 1.

Remember how we created an upgraded spear, but didn't actually do anything with it? Let's change that here:

  1. We add another check inside the touching check, which is an if () else () block in this case.
  2. Here we check whether the enemy touches the gray color using touching color <gray>. This refers to the light gray tip of the upgraded spear.
  3. If so, we use set speed to () with value 4 to temporarily slow down the enemy when hit.
  4. If the color is something else, that is to say, not the upgraded spear, we use set speed to () with value 6.
  5. To allow some time between hit checks, we wait for 0.01 seconds using wait () seconds before running the entire loop again.

The finished script will look like the following screenshot:

Engage thrusters

This game isn't much of a challenge if the boss can't hit the player back. So, we will add a small script that ends the game when the player collides with the boss sprite as follows:

  1. We click on the Diver sprite in the Sprites library to see its script.
  2. Notice that we already created a hit condition for touching the Starfish sprite using the touching block. We just need to add one more touch condition.
  3. We grab an or operator and a touching <Gobo> block.
  4. Place the new touching block in the right slot of the operator.
    Engage thrusters
  5. Then place the entire earlier construction in the left slot.
  6. Now we place this string of four touch conditions in the repeat until condition slot.

That's all that we need to do to add a collision effect with the boss to the game.

Engage thrusters

Objective complete – mini debriefing

That concludes setting up the basic properties of the boss. It will disappear and appear on the screen when required, and it will attempt to start an attack pattern. Of course, it won't actually move because the message receivers and movement patterns haven't been written yet. At this point, we could check whether the hitCount value goes up when we hit the boss with a spear. Shooting a static enemy is a lot easier for testing.

Check the checkboxes for hitCount and speed to see the values change when testing this game.

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

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