Build Your Own Computer Game
We’re going to learn how to build your own computer game! Scratch is a great platform to learn to code because it is a drag and drop environment. You get to explore and discover computer programming concepts without having to deal with syntax and typing.
This is how you build a game called Forest of Danger. This is what the game looks like.
The aim of the game is that the player has to get the bat to the orange whilst avoiding the lightning bolts. If the bat gets to the orange, you win. If you touch the lightning bolt, you lose. Let’s build this game!
First you break the problem down into a series of steps to build the game:
1. Forest backdrop
4. You win backdrop
5. You lose backdrop
6. One lightning bolt
7. Duplicate more lightning bolts
At the Scratch homepage click on ‘Create’ to start a new project. New projects come with a cat as default. Let’s delete the cat.
Select your backdrop for the game. Go to the backdrop library by clicking on the small backdrop icon on the bottom left of the screen. We picked the Forest backdrop but feel free to pick the backdrop you prefer.
The player controls the bat. The aim of the game is for the bat to reach the orange whilst avoiding the lightning bolts.
The bat is controlled by the player pressing the arrow keys. Select the code blocks to tell the bat to move when you press the arrow keys. Use the X and Y coordinates to move the bat up, down, left and right. Test your code by pressing the arrow keys and see whether the bat moves as expected.
You can animate the bat so that it looks like it is flapping its wings.
The orange remains stationary. When the bat touches the orange the player wins the game. You can use an ‘if’ block and a ‘touching’ block to code the orange.
You win backdrop
Create a ‘You win’ backdrop and reference it in your code for the orange. Now test your code. Move the bat to touch the orange. What happens? Does it trigger the “You win” backdrop? Test your code before moving on.
Now when you click on the green flag to start the game, what happens? The game starts with the “You win” backdrop. We now need to give instructions to the game to start with the ‘Forest’ backdrop when the game starts i.e. when the green flag is clicked.
You lose backdrop
Whilst you are in the backdrop section, create a “You lose” backdrop.
There are four lightning bolts that are used in the game however it is best practice to build one perfectly functioning object before it is duplicated. This will minimise work and errors. Test the object to make sure that it works exactly as you want it to before making multiple copies of it.
The lightning bolt does two things:
1. It repeatedly appears at the top of the screen, moves down, then disappears when it reaches the bottom of the screen and reappears at the top of the screen.
2. When the bat touches the lightning bolt it triggers game over, i.e. switch backdrop to the “You lose” backdrop and stop all scripts from running.
Test your code to check that the lightning bolt behaves as you expect it to i.e. in terms of movement and when the bat touches it.
Once you have tested your code and are confident that it works, you can now duplicate the sprite (object).
Duplicate lightning bolts
Duplicate the first lightning bolt as much as you like, we have a total of four lightning bolts in our game.
Test your code
Test your code at each stage of building the game. This helps to identify errors early and stops you from unintentionally magnifying the error because you have continued building the game on top of the error.
That’s how you build your own computer game with Scratch! Can you think of any other games to build? Perhaps a maze game or a quiz game? The sky’s the limit so let your imagination run wild.
Check out our free teacher download. Learn to code with Scratch in 30 minutes.
If you’re interested to find out more