Programming the Racing Game in Scratch

by Noah1194 in Circuits > Software

40077 Views, 5 Favorites, 0 Comments

Programming the Racing Game in Scratch

racer car.jpg
This tutorial will show you how to program a racing game inside of MIT's Scratch.

First....

updated scrach pro.jpg
1) Go to http://www.scratch.mit.edu
2) Search Noah1194 in the search field
3) Click on the racing game and download it.

Starting the Game.

Start script for racing game..png
1) You will notice that in the car sprite there are a bunch of scripts.
2) Take a look at the first one at the top on the left that starts with a "when flag is clicked"
3) The program says: when the flag is clicked set the variable "timer" to 30, make the car in the right costume, and make it go to the right place on the track.

Moving the Car.

moving car script.png
1) Now look at the scripts that start with "when key is pressed".
2) These four commands are the ones that make the car move.
3) They are pretty simple. They just say point in either the right, left, up, or down direction and move that way.

Touching Color Commands.

touching color level.png
touching color place.png
touching color size.png
1) If you scroll down you will see a lot of commands that have the "touching color" commands in it.
2) What those say is, if the car is touching color.... then either go to the next level, or go to a place on the track, or set size, ect.

Timer Variable.

Timer command.png
1) In the car sprite look for a script that has the variable "timer" in it.
2) You will notice that there are commands inside of a "forever" block.
3) What that program says is, when the flag is clicked, wait a second, then decrease the timer by -1. Then in a "if" block it says, if the timer reaches 0, then broadcast game over and set timer to 0.

Changing Backgrounds

switch backgrounds.png
1) Go into the stage sprite and you will see short scripts that start with "when I receive".
2) All those commands are telling the stage sprite to switch backgrounds when each one is received.

Hiding and Showing Sprites.

hide and wait.png
1) Under other sprites, such as the arrows, or the start and finish sprites, are commands that tell it to hind and show.
2) When a sprite is not needed in a track or should come up at a particular time you put the hide command in. If you want it to come up at a particular time you put a hide then wait, then a show.