Scratch is a platform that allows users to express their creativity while learning to code. Scratch Programming is a block-based coding language that makes it simple to create games, animations, and other projects.
With this platform, there are countless opportunities for development, and even those just learning to code or young children can produce engaging games.
One such game is the Car Racing Game, which is also one of the most popular games in Scratch.
This article will show you how to make a Car Racing Game in Scratch, where we’ll also be creating a racing track.
We’ll also learn about basic coding concepts like variables, loops, and conditional blocks in this Car Racing Game.
Table of contents
What is a Car Racing Game?
A Car Racing Game is essentially a racing game in which two cars race on a racing track.
Two players, Player 1 and Player 2, compete in this game by racing around a track. Let’s jump right into the game creation process.
How To Make A Car Racing Scratch Game
First and foremost, let’s create the sprite and backdrop that will be used in this game.
Drawing The Backdrop
Let’s start with the backdrop. To create a new backdrop, select the “paint” tool and then click the “new backdrop” button.
Place your mouse pointer on the “choose a backdrop” button in the lower right corner of the screen. Then select “paint.”
Then we can start drawing our backdrop which will be a racing circuit for our cars.
Drawing The Sprite (Car)
Let’s get to the sprite now that the backdrop has been created. Let’s make our sprite an automobile. Draw a rectangle for the body to start.
You can give it whatever color you want.
Now, letโs move to the tires. Draw 4 more rectangles for the tires.
Then, by clicking the “forward” button, move your body forward of the tires until all of them are behind the car body.
And lastly, draw the car windshield using a rectangle.
Coding For The Car
- Movement of car
First, we must adjust the size of the car so that it does not take up too much space on the screen (the car size here is 25).
Then, using the “go to” and “point in direction” blocks, set the car’s position and direction. As a result, it will begin before the lap line and will face to the right.
Then make it move indefinitely and change direction with each right or left arrow press.
(Note: yellow blocks represent events, blue blocks represent motion, light blue blocks represent sensing, and orange blocks represent control.)
- Lapping System
Before making the code for the lapping system. We have to make a variable for the lap number. Click on โmake a variableโ then give a name to your variable. Here we named it as P1 lap
(Note: P1 = Player1)
Now that we’ve created the variable, we can move on to the blocks. Let’s make it a rule that if the car touches the lap line (white), we get one lap number.
Also, when we first start the game, we must set the lap number to 0. (when green flag is clicked). As a result, the lap number will always begin with 0.
- Start over when touches the grass area
Let’s now modify the car such that it restarts when it strikes the grass. The location and direction must therefore be set back to their initial values. Make sure that the current lap’s number is maintained.
Duplicate The Sprite And Codes For Player 2
To duplicate the “Player1” sprite and codes, right-click on the sprite and select duplicate. As a result, all of the codes and costumes have been copied.
Then, for Player2, change the car body color so that it is clear which car belongs to Player1 and which belongs to Player2.
Change the coordinate of the “go to” block so that it refers to Player2’s starting position.
And change Player2’s control to “a” as the left arrow and “d” as the right arrow. (As a result, we have different control over Player1 and Player2).
Remember to create a new variable for the P2 lap!
Voila! Now your Car Racing Game become a multiplayer game!
Conclusion
Scratch platform lets users create a lot of awesome projects on top of learning computer programming. Because it employs visual block-based coding, it becomes easy for anyone to create projects such as games and animations in Scratch.
Go ahead and create this simple car racing Scratch game and share it with your friends and family.
To get your hands on more such articles, educational content, and free resources on coding for kids, robotics courses for kids, game development, etc., check out the BrightCHAMPS Blog Page now!
Learn Scratch at BrightChamps with its specially designed curriculum that makes learning programming easy for students in Grade 1-12.
BrightChamps also teaches a variety of other programs that help kids build a foundation in computer programming through activities, interactive lessons, and other means.
Frequently Asked Questions (FAQs)
A variable is a type of container that is used to store a value or data.
Because when the car returns to its starting position (before the lap line) and then passes the lap line, the number of laps resets to its previous lap. For example, if a car hits the grass on the third lap, its lap will be 2 (before passing the lap line), and it will return to the third lap after passing the lap line.
Because we don’t want it to continue in its previous direction, set the direction to 90 when in the starting point.