The Spaceship sprite fights enemy sprites with Spaceship Ammo, and enemy sprites attack with the Enemy Ammo sprites.
Spaceship Ammo has one local variable, speed
. The speed variable is how fast this sprite moves. Upon creation, it flies out of the Spaceship sprite and moves straight up until it hits an enemy or the top edge of the Stage.
The Enemy Ammo sprite is very similar to the Spaceship Ammo sprite and is different only in direction, hit target (the sprites it can hurt), and costumes.
Enemy Ammo moves down, but Spaceship Ammo moves up. Also, Enemy Ammo can hit the Spaceship and Spaceship Shield sprites, but Spaceship Ammo can hit enemy sprites. More interestingly, Enemy Ammo, contrary to Spaceship Ammo, is level-aware: it changes the costume based on the current game level. Due to the similarity between Enemy Ammo and Spaceship Ammo, the Enemy Ammo scripts are included in the starter project.
When the game starts, the Spaceship Ammo sprite will only initialize its variables but not participate in the game yet.
To create the code to initialize upon receiving the game_start
message, perform the following steps:
100
.false
.The final script should look like the following screenshot:
The following steps create the code for each Spaceship Ammo clone:
true
.true
, this ammo can destroy multiple enemies. So it uses the change y by (<speed> * <frame_rate>) and repeat until <y position> is greater than () blocks; fill in the value 180
in the repeat until block.false
, the ammo would move up repeatedly until it hits either an enemy or the ceiling. In other words, change y by (<speed> * <frame_rate>) and repeat until (<y position> greater than (180) or touching <Rock>? or touching <Robot > ? or touching <Monster>? or touching <Mother Ship>?.The final script should look like the following screenshot:
If the game is over, each clone will delete itself. Add the when I receive <game_over> and delete this clone blocks.
Next, let's add the scripts for the Enemy Ammo sprite:
-240
and 240
for x and 180
for y. Then, add the go to front and show blocks.10
and 15
.Besides hitting the bottom or the Spaceship, an Enemy Ammo clone is also deleted when the current level completes. Add when I receive <level_up> and delete this clone. The finished script looks like the following screenshot:
We finished creating the scripts for Spaceship Ammo as well as for Enemy Ammo. Now you can test each script by double-clicking on the script. If you double-click on the when I start as a clone block once, one Spaceship Ammo clone will show at the bottom and flies straight up until it hits the top. For Enemy Ammo, the clones will show at the top and fall down until it hits the bottom or a Spaceship sprite.
Global variables are shared by all the sprites, and local variables are for one sprite or clone. You can think of global variables as values that are posted on the bulletin board for all to see. On the contrary, the local variables are like a letter. When a sprite is cloned, that clone contains its own copy of that letter.
3.129.42.243