Introduction:
In this activity you will learn how to create a balloon popping game, in which you have to pop as many balloons as you can in 10 seconds.
Materias
Computer or laptop, scratch
Procedure:
5. We will now add a balloon sprite. To do this we will press “choose a sprite”. You can find this button at the bottom right of your screen.
6. You will then choose the balloon sprite called “balloon1”
7. We will now add a backdrop. To do this press this button. You can find this button at the bottom right of your screen
8. You can choose any backdrop you would like but for this example i’m going to use the backdrop (Wall 1)
9. We will now add code to our balloon. To start off our code we are going to drag out this block from the events command. You can place this block anywhere since we are starting a new code
10. You will now go under the motion command and drag out this block. Place this block underneath the “When … clicked” block. These blocks will attach.
11. You will now go under the motion command and drag out this block. Attach this block to the previous blue block. In the white circle you will type in “45”.
12. You will now go under the control command and drag out this block. Place this block underneath the “Point in direction” block.
13. Go under the motion command and drag out this block. Place this block inside the forever loop block. In the white circle type in “1” for now
14. You will now go under the motion command and drag out this block. Place this block under the “move … steps” block inside the forever loop
Your code should look like this so far
You can test your code by clicking on the green flag at the top of your screen
Does your balloon move slowly? you can change the speed of the balloon by changing the number in this block. For this example I used “5” but you can choose any number. Remember that the lower the number, the slower you balloon will move and the higher your number, the more fast your balloon will move
Did you notice that your balloon flips as it moves around the screen?
We can fix this by clicking on the directions
Then clicking on “Do not rotate”
With the code you have now, your balloon will always start in the same place and move in the same path. Instead of using the same x and y position each time, you can let Scratch “pick a random number” instead. We will add on to our code
15. You will now go under the operators command and drag out this block 2 times. In both of the first white circles type in “-150” and in both of the second circles type in “150”.
16. You will place one of the green blocks in the first white circle next to “x:” in this block. You will place the second green block in the second white circle next to “y” in this block.
It should look like this
If you are confused, your code should look like this
We can use a random number to choose a random balloon colour each time.
17. To choose a random colour we will first start off by going under the looks command and dragging out this block
18. You will drag this block underneath the “Point in direction …” block
19. You will now go under the operators command and drag out this block. In the first white circle type in “0” and in the second white circle type in “1000”
20. You will place this block in the white circle on the purple “change colour effect by …” block. It should look like this
You will now start doing a code to allow players to pop the balloons
21. You will now click on costumes. You can find this at the top left of your screen.
22. Delete the balloon by clicking on the trash can above it
23. Delete the balloon by clicking on the trash can above it
You should only have 1 balloon left at this point
You will now pain’t a new costume
24. To start paining a new costume you will first need to hover over this button
25.While hovering over that button, You will need to click “paint”
26. You should see an empty costume now
27. You will now name this costume “Burst”. To do this you will go to the top of your screen and edit the name.
28. We will now begin to paint our “burst”. We will first click the paint brush icon
29. Click on “Fill” and change the colour to black. You can do this by turning the brightness all the way down.
30. you will now attempt to draw a burst like this. Don’t worry it doesn’t have to be perfect.
31. You will now click back onto “code” So we can add more code to our game
32. You will now go under the looks command and drag out this block. Under the drop down menu select “Balloon1-a”. You will place this block at the start of your code underneath the “when … clicked” block
Your code should look like this
33. We will now add code code to allow the player to burst to balloon. To do this we will first go under the events command and drag out this block. You can place this block anywhere on the blank working space since we are going to start a new code. Make sure you don’t attach this block to your previous code blocks
34. We will now go under the looks command and drag out this block. Place this block under the “when this sprite clicked” block.
35. You will now go under the sound command and drag out this block. Place this block underneath the previous purple block.
36. Go under the events command and drag out this block. In the white circle type in “0.3”. You will then place this block underneath the “start sound … pop” block
37. You will now go under the looks command and drag out this block. Place it under the “wait … 0.3 seconds” block
Your second code should look like this
38. We are now going to add a next code block to our FIRST code. Go under the looks command and drag out this block. You will place this block underneath the “when … click” block.
Your first code should look like this
You can now test your code so far. When you click the balloon, It should disappear and your burst costume you painted should appear for a short period of time. When you click the green flag your balloon should appear on the screen again until you pop it.
We will now do a code to add a score
39. To add a score we will need to make a variable. Go under the variable command and click “make a variable”.
40. You will then name this variable “Score”. Press “for all sprites” then, press “ok” to save your variable.
41. We are going to add a code block to our FIRST code we made. Go under the variable command and drag out this block. Under the drop down menu select “score”. You will then place this block underneath the “when … clicked” block. Make sure this code is added to your first code!
42. We will now add code to our SECOND code. Go under the variable command and drag out this block. Under the drop down menu select “score” and in the white circle type in “1”. You will place this block under the “wait … seconds” block. Make sure this is added to your second code!
Your first code should look like this for now
Your second code should look like this for now
Popping 1 balloon isn’t much of a game, so let’s add lots more!
43. You will first start off by going under the control command and dragging out this block. Place this block anywhere on your empty working space because we are going to start a new set of code
44. You will then drag all these blocks as shown below from your first code, to underneath “when I start as a clone” block.
This is what all your codes should look like so far, so you don’t get confused.
45. We will now be working on this area of code. (This was code 1 until we dragged all the other blocks underneath the “when I start as a clone” block)
46. You will go under the looks command and drag out this block. Place this block under the “set … score to” block.
47. You will then go under the control command and drag out this block. You will place this block underneath the “hide” block. In the white circle type in “20”
48. You will then go under the control command and drag out this block. Place it inside the “repeat …” block.
That area of the code should now look like this now
We will now be working on this area of the code
49. You will go under the control command and drag out this block. You will then take the “hide” block and replace it with the “delete this clone block” that you just dragged out.
That area of code should now look like this
Challenge
To finish off our game we will be adding a timer. We will give the player 10 seconds to pop as many balloons as they can.
Here is the finished code of the timer. You have learned where all the blocks are and how to make a variable so this should be simple. Look at the picture below to see the timer code. (Keep in mind that the timer code will be a separate piece of code. So when you start the code below make sure it isn’t attach to any of the previous blocks we have made)
Your final code should look like this
ENJOY YOUR GAME
POP A LOT OF BALLOONS IN 10 SECONDS!