Introduction to Snap!
In this lesson, you will be learning to use a piece of software called Snap!. You can use Snap! to write your own computer games. Snap! was developed by Jens Mönig and Brian Harvey, and it is based on Scratch, which was developed by the Lifelong Kindergarten Group at the MIT Media Lab. For more information, see http://snap.berkeley.edu.
Snap! runs through a web browser (Chrome is the recommended browser for using the Hummingbird or Finch with Snap!). To open Snap!, go to http://snap.berkeley.edu/snapsource/snap.html.
This is the Snap! window. It has a few different parts. The arrows are called sprites (or turtles), and they are shown in the lower-right corner of the screen. To write a program, you will drag blocks from the Blocks area to the Scripts area. Your program will run in the Stage area.
Moving and Turning in Snap!
Start by dragging a move block into the Scripts area. This block is on the Motion menu. This is your first program! Click on this block to run your program. What does the sprite do?
Exercise: Add a variety of turn and move blocks to your program to make the sprite move in an interesting way. If your sprite moves too far toward the edge of the stage, just click and drag it back to the middle. Change the number in the block and click on it again. What changes? Try a negative number. What does the sprite do?
You write programs in Snap! by connecting blocks together. Try connecting a turn block to your move block. Drag it into your program until it connects to the move block. Click on your program to run it. What happens?
There are two turn blocks, one to turn right and one to turn left.
Exercise: Add a variety of turn and move blocks to your program to make the sprite move in an interesting way. If your sprite moves too far toward the edge of the stage, just click and drag it back to the middle.
So far, you have been running your program by clicking on it. You can also use an event to start a program. An event is an action that the computer can recognize. For example, you might press a key on the keyboard or click on a sprite. Both of those are events.
Click on the Control menu. The top block on this menu is when flag clicked.
Drag the when flag clicked block into your program until it connects to the top of your script. Notice that the shape of this flag shows you that it must be at the top of a script. It can’t be connected below another block.
Now you can run your program by clicking on the green flag at the top of the screen. Try it out!
Another interesting block on the Control menu is the when key pressed block. Use this block to make the sprite move when the spacebar is pressed.
Click on the black triangle in the when key pressed block. A menu will pop up that will allow you to select other keys. Modify your program so that the sprite moves when the right arrow is pressed.
Exercise: You may have already discovered that you can write multiple scripts for the same sprite! You should write four scripts for your sprite. These scripts should enable you to use the four arrows on the keyboard to move the sprite around the stage. Each arrow should correspond to one movement of the sprite. Think carefully about which arrow you will use for which movement. Test your project to make sure that you can move the sprite to any part of the stage.
Saving Your Work
It is very important to save your work often! Otherwise, you might lose something important. To save a new project in Scratch, click on File and then Export project. Give your project a name and then click OK. Your program will be saved as a .xml file. To open a file, select File and then Import.