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.
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:
The following screenshot illustrates the preceding process:
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:
To control the behavior of the script, we will create a few variables.
All these variables are local to a single sprite, so we have to make the proper settings.
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.attack patterns
.pattern1
pattern2
pattern3
With these variables created, we can write a script that sets up all the required values at the start of the game.
40
, so it isn't too big compared to everything else.0
.5
.-90
.200
and 0
respectively.The finished script looks like the following screenshot:
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
and 3
respectively.50
. (This number can be changed to make it easier/harder to defeat the boss.)1
.Remember how we created an upgraded spear, but didn't actually do anything with it? Let's change that here:
4
to temporarily slow down the enemy when hit.6
.0.01
seconds using wait () seconds before running the entire loop again.The finished script will look like the following screenshot:
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:
That's all that we need to do to add a collision effect with the boss to the game.
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.
3.137.220.92