Home

Home

 Print This Lesson


SCRATCH TUTORIAL     SPACE SHUTTLE MISSION STS-2020
Lesson 15     Create Scripts for the Missile Sprite

  • Description. This lesson we will create Scripts for the Missile Sprite.

    If you haven't already, Launch the Scratch program from your desktop.
  • Let's get started!!!

  • We will be using background 5, spacebg. Click on the Stage icon, Select the spacebg.
To get to the Missile sprite interface, in the Sprite list, Click on Missile1 icon

Click on the tab.

  • Create the script.
Description:
When the game starts, we want to hide the Missile.
We want to use the spacebar to fire the missiles.
We need a variable to keep track of the missiles.
We need a variable to tell when the missiles are ready to fire.


Let's create the variables.
In the script block area click on the button
Click on the button


We want the Missile variable to show on the Stage. Click inside the check box to check it

Let's make a variable to tell when the missiles are ready to fire
Click on the button


We do not want the MissilesReady variable to show on the Stage.
Click inside the check box to uncheck it

Let's make the scripts

When the game starts:
Hide the Missile.
Set the Missiles variable to 3
Set the MissilesReady variable to 0.
   The MissileReady variable is like a switch, 0 is off, 1 is on. We need it so the missile dosen't fire whenever you press the space bar, only works when we change to the spacebg background.

Grab and Snap these blocks together, to create the Script.

When the Missile, recieves the message mayday:, set MissilesReady variable to 1.

Grab and Snap these blocks together, to create the Script.

Let's make the script to fire the missiles

This script looks hard, but it just has a lot of blocks, let's see what it does, then we will buid it.

When the space bar is pressed:

If Missiles are greater than 0 and MissileReady equals 1 then,
go to the shuttle, show, subtract 1 from the Missiles
Change the y coordinate by 3, repeat until it touches the Alien spaceship or the edge of the Stage.
If it touches the Alien spaceship add 5 to the score and broadcast the message hit
else (if it touches the edge of the stage) subtract 5 from the score.
Hide and go to coordinates x:0,y:0


This is the script

Let' build it

If it touches the Alien spaceship add 5 to the score and broadcast the message hit
else (if it touches the edge of the stage) subtract 5 from the score.
Hide and go to coordinates x:0,y:0


Grab and Snap these blocks together, to create the Script.

Change the y coordinate by 3, repeat until it touches the Alien spaceship or the edge of the Stage.

Grab and Snap these blocks together, to create the Script.

If Missiles are greater than 0 and MissileReady equals 1 then,
go to the shuttle, show, subtract 1 from the Missiles.


Grab and Snap these blocks together, to create the Script.

When the space bar is pressed.

Grab and Snap these blocks together, to create the Script.


Test: To test all the scripts, click on the Start flag int the top right corner