0% found this document useful (0 votes)
36 views2 pages

2 - RaceGame

Uploaded by

ishanth.satheesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

2 - RaceGame

Uploaded by

ishanth.satheesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

BBC micro:bit – Car Racing Game

The aim of this game is for the player to move their race car left and right using the A
and B buttons and avoid other cars as they overtake. The cars appear at random
locations across the top of the LED grid and move down the grid while the player’s car
remains at the bottom. As they pass each car the score goes up by 1.

Step 1: Initialising the game


Let’s initialise a few variables; score and gameOn, as well as our
main sprite, the player’s car.

This code will loop indefinitely while the game is in play. Once the
game is over it will display a ‘Game Over’ message along with the
final score.

Step 2: Controlling
the main sprite
We are now going to add
two event handlers to
respond to the user
interaction, when the
user presses the button A or B. We will use code to
move the car to the left or to the right by changing
its X coordinate.

Step 3: Adding the first car


The first car called car0 will be positioned at the
top of the screen on lane 0. It will then move
downwards (by changing the Y coordinate of the
car) till it reaches the bottom of the grid. Once at
the bottom of the screen we can check if it is
colliding with the player’s car. If not, we reposition
the car in a random x position at the top of the
screen and give it a randomised delay.

The purpose of the randomised delay is to make


sure that all 5 cars do not all come down at the
same time.
Step 4: Duplicating the code for each car
For this final step we can copy the code from step 3 and paste it for the other 4 cars (make sure to rename the sprite
car1 to car4 for each code block).

Extension Tasks:
• Use forward and backward tilt to make the car move forward or backwards, be careful to make sure that it
doesn’t move off the screen.
• Change the game so that every time you have passed 10 cars you move to the next round and the cars move
faster.
• Change this game into a “Catch the fruit” game, where instead of avoiding the falling sprites the player should
try to catch them and score a point each time they do so.
• Can you come up with your own game? Write out a set of instructions of how you play and win the game, and
then work together to create the code.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy