Building a simple game with Scratch
- Reset the program
Choose "new" from the file menu. Do not save the file.
- Be sure the "motion" tiles are visible
The blue motion tiles should be visible. Click on the motion
button if necessary.
- Experiment with the tiles
Double-click on the 'turn 15 degrees' tile. Watch what happens
to the cat.
- Put the 'move 10 steps' tile in the script area
the center area is where you build scripts
- Connect the 'turn 15 degrees tile
When a white bar appears, the tiles will snap together
- Surround the tiles with the 'forever' loop
Switch to the orange 'control' tiles. Drag the 'forever' loop
to the center. Drag the connected tiles so they are in the
'alligator mouth' of the loop.
- Add the 'When flag clicked' tile
This tile is shaped like a hat. It sits on top of the other
elements
- Test your program
Click on the green flag (upper right corner) Click the stop sign
when you're done.
- Get rid of the blue blocks
Now we're going to turn this animation into a game. Drag the blue
tiles into the tile area to delete them.
- Add an 'if' block to the script
You should still be showing the orange tiles. Find the 'if' block
(not 'forever if' or 'if - else' - They're a bit different.)
Place the if block inside the forever loop
- Add a condition
The hexagon shape inside the if statement requires a new type
of statement. Go to the light blue 'sensing' tiles.
- Find the keyboard sensor
Locate the tile that says 'key <space> pressed?'
Place this tile in the appropriate part of the if tile
- Test for the right arrow
Use the small triangle on the key tile. Click to get a menu of
keys, and choose 'right arrow' from this menu.
- Add 10 to x
If the user clicks the right arrow, we want to move to the
right. Go to the 'motion' tiles. X determines side-to-side motion.
Place the 'change x by <10>' tile inside the if block.
- Test the program
Use the green flag to see if the program works. The cat should
move to the right when the right arrow is pressed.
- Copy the if block
Move the mouse to the if statement and right-click. Choose
'duplicate' from the menu. A copy of the if block will appear.
Drag this under the first if block (be sure the ifs are NOT nested.)
- Change the second if statement
The second if statment tests for the left arrow
- Move the sprite by -10
Move the sprite to the left by changing x a negative amount
- Add vertical motion
See if you can make the sprite also move up and down
Bonus challenges
Try these additional challenges if there's nobody waiting for a turn
or at home on your own:
- Build a target sprite
Add a new sprite. You can get one from the library or
draw your own.
- Animate your sprite
Each sprite can have multiple 'costumes' or images. You
can make your sprite dance or whatever by flipping through
the costumes
- Have a sprite move on its own
Make the target sprite move all on its own.
- Wrap around the edges
It's easy to make a sprite bounce. Can you make it wrap?
- Add a timer and scorekeeping
Give your game points and a time limit