Page 146 - KEC Khaitan C5 Flipbook
P. 146
Example:
When player car touches enemy car, restart. HANDS-ON PROJECT
If player car successfully moves forward,
increase score. PROJECT NAME: Build a Car Racing Game
Objective:
IMPLEMENTING DYNAMIC GAME PROGRESSION
Build a fun car racing game where the player controls a car to avoid obstacles.
A racing game becomes more engaging when it has increasing difficulty and score tracking.
Use arrow keys to move left and right, dodge enemy cars, and aim for high scores.
Increasing Difficulty
Add features like restart, randomized obstacles, and increasing difficulty to keep the
The diffuclty of the gamecan be increased by: game exciting.
Increase the speed of enemy cars over time. Screens Employed in the Game
As the score increases, enemy cars will move faster. We use an If condition to check if
the score reaches a certain value and then increase speed.
Introduce new obstacles at higher levels.
When the player reaches a score milestone, a new obstacle appears on the track. The
obstacle moves downward, like enemy cars, to make the game harder.
Scoring System
Start Screen Racing Screen Restart Screen
We can use scoring system to make game more engaging by:
Step-by-Step Instructions
Award points for successfully dodging obstacles.
Step 1: Setting Up the Road and Player
The player moves forward (upward) to avoid obstacles. If the player reaches the top,
they get +1 point. The player's car resets to the bottom for the next round. Create the Road Sprite:
Display the score on the screen. var road = createSprite(200, 200);
When the score increases, update the text label on the screen. The text label always road.setAnimation("road");
displays the current score. road.scale = 1;
o This creates the road background at the center of the screen.
REVISIT o Tip: Choose a road background sprite from the animation library.
o Display results on a screen or output box.
▶ Sprite Lab is a great tool in Code.org for creating games using sprites, animations, and
interactions. Create the Player's Car:
▶ Sprite Lab offers tools to create and manipulate sprites, detect collisions, and implement var player_car = createSprite(200, 350);
game logic easily.
player_car.setAnimation("car");
▶ Event handling enables the game to respond to player inputs.
▶ Collision detection is essential to check if the player’s car crashes into an obstacle. player_car.scale = 0.6;
▶ A racing game becomes more engaging when it has increasing difficulty and score tracking. o The player's car is positioned near the bottom center of the screen.
o Tip: Choose a unique car sprite to make the game more personalized.
144 Premium Edition-V

