Scratch game making tutorial 131

Pentagons

In this tutorial you will make a game in which the player must spin falling pentagons to ensure that their face down side colour matches the colour of the ground when they touch.

In the image to the right you can see that only the middle pentagon colour matches the ground colour.

 

Complete these steps ..

 

1. Create a new game and right-click the cat thumbnail to delete it.

Now, select the stage. Select the Backgrounds tab and then click the Edit button. Use the paint bucket tool to paint the stage black.

 

 

2. Select the stage's Scripts tab and add these scripts to begin and end the game ..

 

 

3. Our game needs some variables. Select the Variable scripts and then create the following variables "For all sprites"..

Here's what the variables are for ..

Variable name Description
Countdown The player will have a 120 seconds countdown to collect as many points as possible.
Fall speed The speed with which the pentagons fall will increase as the time runs out, thereby making the game harder
Ground costume number This will hold the number of the ground costume (colour) so it can be compared with the falling pentagon costume (colour) when they touch
Pentagon costume number This will hold the number of the falling pentagon costume (colour) so it can be compared with the ground costume (colour) when they touch
Points This will record the number of times the falling pentagon costume (colour) matches the ground costume (colour)

 

Untick all the variables except "Points", then right-click the variable display on the stage and select "large readout" ..

Position the display in the top left corner of the screen so the player can see how many points they have scored.

 

 

4. Now add a script to the stage to set "Points" to zero when the game begins ..

 

 

5. Let's create a script that makes the pentagons fall faster the longer the game is played.

Add this script to increase the fall rate every 10seconds ..

 

 

6. Our game needs a time limit. Let's add a script for a countdown and give the player 2 minutes to collect as many points as they can ..

 

 

7. Select File>Save and save your game. Name it "Pentagons".

 

 

8. Download, save and the use the "Choose new sprite from file" button under the stage to add these sprites ..

 

 

9. Select the Ground sprite and switch to its costume tab ..

Notice how there are five costumes and that each has a number and a name. For example costume 2 is also called "green".

 

 

10. Switch to the Ground sprite's script tab and add this script to locate the sprite correctly ..

Press the "B" key on your keyboard and the sprite should jump to the bottom of the stage. It's not important which costume is showing, we're going to select a random costume with the next script.

 

 

11. We need a script for the ground sprite which chooses a random costume and changes it at a random time. We also need to record the current costume number in a variable so we can compare it to the pentagon costume to see if it matches or not.

Add this script ..

Notice how the ground costume number is always recorded in the "Ground costume number" variable each time the costume is switched.

Temporarily turn on the "Ground costume number" variable display so you can see it on the stage and then press the "B" key on your keyboard. You should see the costume changing every few seconds.

Press "E" to end your game and turn the variable display off again.

 

 

12. Press "E" to end your game and then use File>Save to re-save your game.

 

 

13. Select the "Pentagon 1" sprite and add the first script to set it's size and starting direction ..

 

 

14. Compare the Ground costumes and the Pentagon costumes. Notice how their colours/numbers match ..

 

 

15. We need a script that makes the pentagon hide, go to the top of the stage, wait for a random time, show, and then fall until it touches the Ground sprite.

Also, when it touches the Ground sprite we need to know if their colours match and if so add a point.

Add this script ..

* Notice how we have had to use a "join" script block to convert the "Fall speed" into a negative number. This is because the pentagon is falling down the stage (y changes by a minus number).

 

 

16. Use "File>Save" to re-save your game and then press "B" to test it. The Pentagon should fall, hide when it reaches the bottom of the stage and then fall again.

 

 

17. The player needs to be able to spin the Pentagon if the colours don't match. Add this script ..

* Notice how "Pentagon costume number" is constantly updated with the costume number of the sprite.

* Also notice how we are using two simple repeat loop animations to make the spin more fun.

 

18. Press "B" on your keyboard to test the game. Move your mouse-pointer over the Pentagon when you need to spin it.

 

 

19. Press "E" to end your game. If the Pentagon is working fine you can move on to the next step. If not, stop, go back and fix any problems.

 

 

20. One Pentagon is not enough, we need three. Duplicate "Pentagon 1" twice and re-name the duplicates "Pentagon 2" and "Pentagon 3".

 

 

21. Select "Pentagon 2". Pentagon 1 falls down the left side of the stage. We want "Pentagon 2" to fall down the centre.

Find the "go to x:-140 y:200" script block and change x:-140 to x:0.

 

 

22. Select "Pentagon 3". We want "Pentagon 3" to fall down the right side of the stage.

Find the "go to x:-140 y:200" script block and change x:-140 to x:140.

 

 

23. Use "File>Save" to re-save your game and then press "B" to test all three pentagons.

 

 

24. Press "E" to end your game. We need to script the "Game over" sprite. Select it and add these scripts ..

 

 

25. Use "File>Save" to re-save your game. Well done. You have finished this tutorial. Can you add things to make the game better?