Scratch Exercise 2: Creating a Simple Sight Word Game using Random Motion and Conditional Statements.

The real power in programing lies in the ability to have objects ("Sprites") in your world interact with each other and cause changes in behavior or action.  In Exercise 2 we will learn how to:
• Have a Sprite move randomly about the screen on its own power.
• Create an "If" statement to have the program do an action when the Sprites touch.

 Programming Tip:  Scratch uses a programming technique called "Object Orientated Programming."  Object Orientated Programming treats each "object" (Sprites in the case as Scratch) as a seperate unit on which instructions or code direct the action.  Think of your Sprites as little robots that you will command to do certain tasks.  Objects in your program can interact with each other or broadcast messages to other objects.  In Exercise 2, the "chaser Sprite" (the one you control with the arrow keys) pursues the "Sight Word Sprite" (which moves on its own.)

 Basic Game Types: Chase, Run Away, or Maze Games Shooting or Projectile Games Racing Games

Step 1: Create a new Sprite.

1. Open Scratch
2. Click the "Open" button and navigate to your "Lastname Scratch Exercise 1."  Select "Open" to load your program.
3. Click the "New Sprite" icon.
4. Click the "Costumes" tab for Sprite 2

5. Click "Paint" next to "New Costume:"

6. You now have the "Paint" area where you can use basic drawing commands to make your own characters.  We are going to type the word "after" for a sight word.  Click the text tool:  (The Letter "T")

7.  Type the word "after."  Click "OK"

8. The "after"  appears  in place of the cat. Hit the "delete" button next to costume 1 and costume 2 to eliminate the cast costumes.

Step 2: Making the "after" move about the screen under its own power.

 Programming Tip:  Sprite's locations are based on a coordinate plane grid that measures from -240 to 240 on the x axis and -180 to 180 on the y axis.  A Sprite's current location is shown beneath the "Status" area in the center pane.  To make "after" move by itself, we must write a command to make random numbers for the following values: x axis y axis speed

9.  Click on the "Scripts" tab.
a. Click the yellow "Control Button"
b. Drag the: button to the scripts pane. (This command directs code to start when user clicks the "green flag" to run the program.)

10. Drag a  (forever tile) to the scripts area because we want this action to continue as long as the game is running.

11. Click the "Motion" button.  Drag the "glide '1' seconds to 'x' 'y'" tile to the scripts area.

12.  We now need some values.  Click on the green "Numbers" button. Drag a "pick random '1' to '10'" tile to the scripts pane.

13. The green "pick random" tile generates a random number in the range of the tile.  We will use this tile to select an x value.  Type "-240" in the first block and a "240" in the second block.

14. Drag another "pick random" block to the scripts area and type "-180" and "180" for the y value.

15. Drag another "pick random" block to the scripts area and type "1" and "3" for the seconds value.

16. These commands still will not work until we "click" them together like puzzle parts.  Drag the "-180" to "180" green block into the y value of the "glide" command:  (Don't worry if you can't see the whole tile.)

17. Drag the "-240" to "240" value into the x value of the "glide" command.  Drag the "1" to "3" into the "secs" value. Again, don't worry if you can't see the whole tile.

18.  Almost done!  Drag the "glide" tile inside the "forever" tile.

19.  Connect the "forever" tile to the "Green Flag" Tile.

20.  Time for action!  Click the green flag icon and watch you "after" float around the screen!

21.  Click the "Save" button!

Step 3: When your Sprite touches the "after," an action will happen (sound will play).

To accomplish this step the "after" sprite will need to know if it is "touching" Sprite1 and an action to do once they touch.  The sequence of directions will go something like:

If "after" is touching Sprite1 - then play sound.

We will use the following things for this step:
• "forever if" command
• record sound
• play sound command

22. First we will record a sound.  Focus on the "after" sprite by double clicking on it.  Then click the "Sounds" Tab

23.  Click the "Record" button.  The sound recorder window appears.
a. Click the red circle to start recording.
b. Say: "after"
c. Click the black square to stop recording.
d. Click "OK"

24. Your new sound will appear in the sound window.  Change the name of the sound to "after."

25.  Now we have the sound.  Next, click on the "Scripts" tab to bring up the code tiles.  Drag a tile to the Scripts pane.

 Remember: If you want an action to start when the program starts - use a tile.

26. Drag a tile to the Scripts pane.

 The "forever if" tile sets up an argument that starts a specific action if the conditions of the argument are met.

27. We are going to use the "sensing" button to "sense" if "after" is touching "Sprite1."
a. Click on the "Sensing" button
b. Drag the "touching _" over to the scripts pane
c. Use the black triangle to call a list and select "Sprite1"

28. Drag the "touching" tile into the hexagon shape in the "forever if" command.

29. Now we have the statement that goes like:

 Forever: If "action" is touching Sprite1, Then . . .

We need to put an action inside the "forever if" statement.  This is where we will put our sound.

30.  Click the "Sound" button and drag the "play sound 'pop' and wait" tile to the scripts window.  Use the pull down menu to select the sound "after" from the list.

31.  Almost done!  (Really!!)  Put the purple "play sound" tile inside the "forever it" tile.  Connect the "forever if" tile to the "When Green Flag Clicked" tile.  It should look like this:

32.  You are done!  Click "Save" and then click the Green Flag to start your game.  Chase the "after" with your Sprite and see if the sound works!

33.  Question:  Can I make my characters bigger or smaller?  Yes!  Use the "Grow" or "Shrink" icons to change size.  Click the icon and then click your Sprite.  I used the "Shrink" to make my dog smaller.

34.  There are many, many options and possibilities for making games with Scratch.
Check out: www.scratch.mit.edu for more game ideas, guides, and tutorials!