To prepare for the upcoming boss battle (next project), it's a nice touch to power up the player character. A power-up system also offers a better reason for shooting enemies apart from the need for survival.
We will assign a score value to each enemy type. The player can increase the score by shooting the enemy of the corresponding type. When the player has defeated enough enemies, the spear will be powered up in some way.
scoreRed
scoreBlue
scoreYellow
0
as shown in the following screenshot. The best place to do this is inside the stage object.1
point in the change <scoreRed> by () block as shown in the following screenshot:It should be obvious that the scoreRed
variable is meant for a red starfish. For the other two colors, we would use scoreBlue
and scoreYellow
variables respectively.
Now that the score values are increasing as enemies are defeated, we can use those values to increase the power of the spear. Each score value/color will have a different effect on the spear. These effects are as follows:
Let's start scripting the scoring system into the spear sprite. We will tackle the scoreRed
functionality first. As the scoreRed
value increases, spears will be spawned at a faster rate. We put a limit of 30
on the value to prevent the spawn rate from increasing to absurd levels.
scoreRed
is less than 30 by entering 30
in the scoreRed < () block. We now allow the script to calculate the spawn rate.scoreRed
value as follows:scoreRed
value by 30
.1.5
.The order of the preceding calculation operators is very important. The operator blocks will be processed from the innermost block to the outer blocks. The result is the number of seconds we have to wait for a new spear to appear.
0.5
seconds when the scoreRed
value exceeds 30.Next, we will handle the scoreBlue
effect. For this effect, we need to draw a second costume as follows:
basic spear
. The second sprite will be called ice spear
.scoreBlue
value. An else () block is not needed in this case.29
in the scoreBlue > () block.The script for the scoreYellow
value is the most complicated. Not only do we need to create multiple clones when the score reaches a certain value, but we also need to reposition and angle the clones so they don't overlap on exactly the same spot.
When the score reaches 15, we will start creating two spears at once. We will angle them outwards a bit, so they move forward in a V shape.
When the score reaches 30, we will create three spears at once. One spear will move straight ahead, while the other two will move outward in a V shape.
scoreYellow
is greater than 14 by entering 14
in the scoreYellow > () block.15
in the turn <counter clockwise> () degrees block to turn the sprite upwards a bit.30
in the turn <clockwise> () degrees block to angle the same distance downwards.We leave this script for a moment before we place it in its proper spot.
Now on to scripting what happens when the scoreYellow
value reaches 30.
29
instead of 14.10
to move the upward angled clone up a bit.-20
to move the downward clone down an equal distance from the original position.That completes our scripting for the scoreYellow
value. The completed result will look as shown in the following screenshot. Make sure that all blocks are sorted in the correct order or the script might behave strangely.
Test the script to see the scores increase as you shoot enemies. Also note how the behavior of the spear changes as you reach certain score values.
The following is a screenshot of the entire stack of scoring scripts we just built. It looks quite intimidating when viewed as a whole, but because we broke it down into separate steps, it became a lot easier to deal with.
If you have trouble staying alive while testing this script, detach the stop <all> block from the diver script. This will prevent the game from stopping when the diver is touched by a starfish.
The order in which the condition checks for the scoreYellow
value are placed is very important. Since the score is increasing from 0 upwards, we first need to check the highest value (> 29), which is the last condition to be achieved. When this condition is not met, the script will then check if scoreYellow
has reached 15 yet. And if that's not the case either, it will default the basic, innermost, else condition.
If we switched these checks around, the >29 condition would never be reached because the >14 condition would resolve and throw us out of the loop before we reached the other condition check.
3.144.82.21