Now that we have a working version of our game where we can race around our track, we can start to think about adding more features to our game. The features we are going to add are:
- Anti-cheating so that you can’t cut out half the track
- Lap counter so that you know who is winning
- Game over screen, displaying who has won
Stop them cheaters!
You may have already realised that there is one potential problem with our plan to count laps – people can cheat by going across the grass! So how do we stop this? Well we simply add a new obstacle to our game – the brown wall of doom.
The idea here is:
- if the car touches the brown obstacle…
- the car goes back to the start line.
See if you can add some code to get this to work.
Once you have done it, check it against my solution below!
Step 1 – Add a finish line sprite
The first we need to do here is add a finish line sprite, in a bright colour. This allows you to test your code and get it working. You can also change it to a different colour later!
Step 2 – Center your finish line sprite
Once you have added you finish line sprite, make sure that you set the center of the sprite to the center of the pink bit.(see below)
Step 3 – Add the lap counting script
The lap counting script needs to check 2 things.
- If the player crosses the line from above, add one to the player’s lap count.
- If the player crosses the line from below (cheating) move them back to the start line and point them in correct direction of travel.
Ending the game
Ending the game
Now that we have a lap counter we can add one more feature to our game – a game over and winner screen.
Step 1 – Add 2 more backdrops to your game
For our game-over screen we will need two more backdrops – one for each player.
Once we have added the backdrops it will be a good idea to rename the backdrop to a meaningful name.
Step 2 – Add the game over checking script
Now you need to add a script that checks to see if a player has reached 4 laps ( in a 3 lap race). If so, change the backdrop to the game over screen (player1 or player2 screen).
Step 3 – Hide the other sprites
Add a script that hides all the other sprites, so that the game over screen is not cluttered!
Note! You need to add the step 3 script to all the other sprites, otherwise they won’t hide!
Add some obstacles that appear at random. If you hit them you either:
- Return to the start of the lap
- Get frozen in position for a second.
- Move faster.