Shield protects and is also protected by the Spaceship. Each time the enemy sprite collides into it, Shield will lose one grid of power, displayed by Shield Life.
When the power is gone (all red), Shield is destroyed and the game is over.
Shield Life displays the shield power grid by changing its costumes, each at a power grid damage level. The technique to display damage level with costumes is to match the costume number with the number of hits. Scratch costumes start from one, instead of zero, so costume#1 depicts zero hit, costume#2 for one hit, and so on.
Shield Life has two local variables: num_shield_hits
and num_max_hits
. The number_shield_hits
variable tracks how many hits the Shield sprite has suffered, and the num_max_hits
variable tells the maximum number of hits that Shield can take before its complete destruction.
The following steps are used to build the scripts for the Shield sprite:
7
and -110
respectively. Finally, add show.The final script looks like the following screenshot:
Next, we will create the scripts for the Shield Life sprite.
Before the game starts, this sprite will hide. At the start of the game, it initializes its local variables.
The following steps handle the <green flag> click and game_start messages:
-51
and -120
, then set <number_max_hits> to () with the value 7
, and set num_shield_hit to () with the value 0
. Next, add switch costume to <0 hit>, then go to front, and show.During the play, these sprites process four broadcast messages: shield_hit, shield_destroyed, life_power_up, and level_up.
The following steps build the required scripts:
1
. Then, add switch costume to (<num_shield_hit>+()) with the value 1
. Add an if () then condition block. Check whether the number of hits the shield has taken is greater than the number of maximum hits it can, by using the <num_shield_hit> is greater than <num_max_hits> - 1 block, and then add the broadcast <shield_destroyed> block.0
. Then, update the look using switch costume to <0 hit> and show.The finished script will look like the following screenshot:
We added scripts to the Shield and Shield Life sprites. The Shield sprite makes the game more dynamic and interesting, whereas the Shield Life sprite displays the life statistics visually and in a more lively manner.
During the game, a gamer needs to track not only the power level as shown in the Shield Life sprite but also the score. Space Age displays the score on a scoreboard using three sprites, one for each digit. They are complete sprites that work right out of the box. The Hundredth sprite displays the hundred's place, the Tenth sprite displays the ten's place, and the One sprite displays the one's place. Just like the Shield Life sprite, each scoreboard sprite has costumes that matches the shown values, as shown in the following diagram:
To display numbers from 0 to 9, all the three sprites have costumes ranging from costume#1 to costume#10, with costume#1 displaying the number 0 and costume#10 displaying the number 9.
For example, to display the score 257, the Hundredth sprite would switch to costume 3, the Tenth sprite to costume 6, and the One sprite to costume 8.
18.191.181.36