Directions for Sound Racer in Scratch

1.  Select a Car Sprite (Painting or Drawing)

2.  Name your Sprite.  (I chose "Car")

3.  Click on the Variables Tab and create a variable just for the Car Sprite called "CarTurn."

Now we want the car to turn right and left when we press the Arrow keys.  We are going to use a more complicated technique to give us better turn control.  The pseudo code for this would be:

When Right Arrow pressed:
    repeat until Right Arrow not pressed:
        CarTurn = CarTurn + 0.2
    CarTurn = 0

4.   Make sure you are focussed on the "Car" Sprite.  Drag a green "not" block from operators and a light blue "key pressed" block from sensing.  Select "right arrow" on the "key pressed" block.

5.  Slide the blue "key right arrow" pressed into the green "not" block.

6.  Drag a "repeat until" block onto the Scripts Pane.

7.  Slide the "not key right arrow pressed?" into the "repeat until."

8.  Drag a "change CarTurn" block from variables onto the Scripts Pane.  Change the value to "0.2"

9.  Slide the "change CarTurn" block into the "repeat until" block.

10.  Drag a "set CarTurn" block onto the Scripts Pane.  Set the value to "0"

11.  Connect the "set CarTurn to 0" to the "repeat until."

12.  Drag a "When key pressed" onto the Scripts Pane.  Change the key to "right arrow."

13.  Connect the "When right arrow key pressed" block to the "repeat until" block.  Finished script should look like this:

14.  Create additional scripts for the left arrow key.  It should look like this:

Do not worry that the car does not turn yet.  The above scripts only set the turn value.  Now that we can set the car turn to right and left with the arrow keys, we will now create the scripts that move and turn the car.  The pseudo code would be:

When Green Flag Clicked:
       Turn CarTurn Degrees
       Move forward 10 steps
       If on edge, bounce

15.  Drag a "when green flag clicked" and a "forever" block onto the Car's Scripts Pane.

16.  Drag a "turn right degrees" block onto the Scripts Pane.  Put the "CarTurn" variable oval into the "Turn" block.

17.  Slide the "turn CarTurn degrees" block into the "forever" block.

18.  Drag a "move 10 steps" and an "if on edge, bounce" block onto the Scripts Pane.

19.  Slide the "move" and the "if on edge" into the "forever" block.

Click the Green Flag.  Now the Car will move and you can steer it with the arrow keys.  The next steps will allow the user to control the speed of the car with the microphone input.  The louder the sound - the faster the car. 

20.  Drag the "loudness" block from sensing into the Scripts Pane.  Drag a divided by and an addition block from operators into the Scripts Pane.  Type a "2" into the "divided by" and a "1" into the addition.

21.  Slide the "loudness" block into the "divided by"

22. Slide the "divided by" into the addition.

23.  Slide the "loudness/2 + 1" block into the "move" block.  Finished Script should look like this.

24.   Add background track and other race cars!  Note on the example how the car "bounces" off the sides fo the track.  Examine the "Line Follower" program for some hints on how accomplish this.

Scratch Line Follow Program Directions