Create a Scratch game that tests your skills at parking. Will you get your Scratch driving licence?
In this tutorial, we’ll be making a basic parking Scratch Game using colour-coding. Our game is called Parking Mania.
Scratch is a child-friendly programming environment which is developed by MIT. You can create games, music or even apps in the platform, and it’s well used in ICT lessons in schools.
For this guide, you will need to follow some easy steps to create a simple but effective game. We will also be using angles – so thanks to Miss Skelton, the author’s maths teacher.
Download the assets from the list on the left and import the car park backdrop. You will need to add the coin and car sprite next (and change them to the desired size using the shrink icon in the top bar) or create your own to make your game unique. Maybe you want to replace the blue river on the backdrop with a pink river, or replace the trees with footballs?
Let’s make sure the car doesn’t start up near the coin or on the grass. Instead, it should appear at the start line. You will need to get the when green flag clicked block, then attach a go to block and replace the number in x to -229 and y to 24. We all want a fair chance of getting our driving licence.
Let’s get the car on the road. With the car sprite selected, get a when green flag clicked Events block, then attach a wait 5 seconds block followed by a forever Control block. Inside the latter, place a go to mouse-pointer Motion block. This bit of code will make sure that when the green flag is pressed, it will wait five seconds so the user has the chance to get the mouse ready; then, after the five seconds, the car will forever follow the mouse-pointer.
Next, get another when green flag clicked block and attach a forever block. Inside the latter, place an if then block. In its small hexagonal field, add a touching color Sensing block; click its blue square, then the green grass of your course on the stage. In the gap of the if then block, place a say Game Over for 2 seconds Looks block, then attach a go to x: -229 y: 24 block followed by a wait 5 seconds block. After that block, insert another forever block and inside that, place a go to mouse-pointer block. This chunk of code will make sure that when the green flag is pressed then if the car ever touches the dark green grass, the car will say ‘Game Over’ for two seconds, before then going back to the start, and it will forever follow the mouse-pointer.
Here’s a challenge: can you use a broadcast block so that now it will repeat this if you crash again? At the moment it only tells you ‘Game Over’ once and after that it will let you crash as much as you want.
Now we insert the last bit of code for the car sprite. Insert a when green flag clicked block, then attach a forever block. Inside the latter, place an if then block. In its hexagonal field, add a touching Sensing block; click its drop-down to change it to Sprite 2 (or the name of your coin sprite). In the gap of the if then block, place a say You Win for 2 seconds block, then attach a stop all block. This bit of code makes sure that once the green flag is clicked, then if the car is touching the coin, the car will say ‘You Win’ and the game will stop.
We don’t want to cheat, so let’s make sure we don’t get flying money. For the coin sprite, add a when green flag clicked block, then attach a forever block followed by a go to x: -228 y: 15 block. This piece of code will make sure the money will forever stay in the parking space, but remember to change this code if you have made your own course.
This is the only bit of code you will need to create your basic game:
You have now created a very basic parking game. We’ve made it fairly simple, so you should be able to code it within an hour and play it. Have a go on the game and see if you can get your driving licence – or should you just stick with a bus pass?
Now it’s your turn. Here are some challenges for you to complete. Can you create multiple levels? Why not add a coin variable? Instead of the car saying you have lost or won, why not make a backdrop for it? Why not, when you pass, create a driving licence? Otherwise, change it in any way you want.