Published on June 4, 2016
1. Making a Racing Game in Scratch By Douglas Mawrey
2. Getting Started Log in to Scratch, then go into your projects and create a new project. Name it something along the lines of “Racing Game” so you and other people know what it is.
3. Making a Racetrack Click the “Paint new backdrop” button in the bottom left of the screen to open a window where you can draw a racetrack. While drawing, make sure you are always in “Vector Mode”, otherwise, click “Convert to Vector” Keep one main color as the color of the racetrack, we will use this color to check what the car is touching later on.
4. Making a Car Next, right click on the cat and click delete. Click on the “Paint new sprite” button and draw a racecar. Make sure the car isn’t too small to see well or too big to fit on the track and make it face right. Once you are done drawing, click the “Set costume center” button at the top right of the screen and make sure the black + lines up with the center of your sprite.
5. Making the Car Move To make the car move, we need to drag some blocks to make some code. In the scripts tab of your car, use the blocks on the left of the screen to make this piece of code. Each colored piece can be found in the different colored sections on the left. To change “key ‘space’ pressed?” to up arrow, click on the black arrow next to the name of the key to choose the key you want.
6. Making the Car Move Right click on the top of the group of code and click duplicate. Then, attach the new group of code to the bottom of the first group. Change “up arrow” to “down arrow” and turn right to turn left.
7. Making the Car Move To finally let the car move, make a new piece of code with a start block and a forever loop. Next, drag the code you put together before into the forever loop. Now, hit play and use the arrow keys to drive the car. + =
8. Variables Variables store information that we can use throughout the game. For this game, we are going to use a variable named speed to change the speed of the car.
9. Using Speed We want the car to slow down when it is driving off-road. To do this, we are going to make a new script that sets the normal speed when the game starts. The script then checks if the car is touching the road using if/else and a color sensor, and if it is not, changes the speed to the lower number. We also need to add speed into the movement code where 10 and -10 used to be, and multiply speed by -1 to make the car move backwards for down arrow.
10. Laps Draw a new sprite that can serve as a start line for your race. Make it just wide enough to cover the track left to right. Duplicate the sprite, and put the copy on the other side of the track. If you like, you can make the start line look different from the midpoint line by coloring it differently.
11. Laps To make the laps work, we need to add 3 pieces of code to the two different lap parts. We need a new variable and to use broadcasts which send messages to the other sprites.
12. Starting the Game Drag the player just behind - but not touching the start line. After this, if you drag in the block, it will have the x and y of the car filled in automatically. We put this extra piece of code on the player in order to make it start at the start line at the beginning of each game.
13. Timed Games To add a timed option to the race, add this code to the stage. This code asks the amount of time you want to race for, and if you enter “forever” or “Forever”, it doesn’t time you. The driving script on the car must also be changed, replacing the When Green Flag Clicked with When I Receive “Start”.
14. Boosts In order to add a boost power up, a new sprite must first be drawn. These two scripts will then need to be added to the new sprite in order to make the boost spawn, stay for 3 seconds, and disappear. The Boost variable must also be made.
15. Boosts Some code on the player must also be changed in order to make the boost work. The code on the left must be changed to look like the code on the right allowing the player to activate the boost by pressing space.