2 - RaceGame
2 - RaceGame
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.
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.
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.