Activity – 4 (Archery)

Introduction:

In this activity you will learn how to create an archery game, in which you have to shoot arrows as close to the bullseye as you can


Materials

Computer or laptop, scratch


Procedure:

  1. Make sure you are signed into your scratch account. (see page 2)
  2. In your search bar type in rpf.io/archeryon
  3. At the top of your page press “remix”

4. We will now begin to code our archery game.

5. To begin this code we will first start off by going under the events command and dragging out this block. You can place this block anywhere because we are starting a new code.

6. You will then go under the events command and drag out this block. Press the drown down menu and select “New message”. You will then type in “New Arrow”. You will then press okay to save your message. Drag this block underneath the “when… clicked” block. They will attach.

7. You will now go under the events command and drag out this block. You will place this block anywhere because we are starting a new code again. In the drop down menu select “new arrow”

8. You will then go under the motion command and drag out this block. In the first white circle next to “x:” you will type in “-150”. In the second white circle next to the “y:” you will type in “-150”. You will then place this block underneath the “whenI receive new arrow” block.

9. You will then go under the looks command and drag out this block. In the white circle you will type in “400”. You will then place this block under the previous blue block.

10. Click on the green flag to test your game so far. You should see your arrow get bigger and move to the bottom left of the stage.

11. We will now add code to the arrow so that it glides randomly around the stage forever. We will do this by dragging out this block under the control command. You will place this block underneath the “Set Size to” block.

12. You will then go under the motion command and drag out this block. In the first white circle next to “glide” type in “0.5”. You will then place this block inside the forever block.

13. You will then go under the operators command and drag out this block. In the first circle you will type in “-150” and in the second white circle you will type in “150” you will then place this block inside the white circle next to “secs to x:”.

14. You will then follow the same steps from #13 but place the next block next to the “y:”. It should look like this

15. Test your game again, and you should now see your arrow move randomly around the stage.

16. You will now do a code to shoot the arrow when the spacebar is pressed. To start this code off we will go under the events command and drag out this block. You can place this block anywhere because we are starting a new code.

17. You will then go under the control command and drag out this block. Under the drop down menu select “other scripts in sprite”. You will place this block underneath the “when space key pressed” block. Test your project again. This time, your arrow should stop moving when the space bar is pressed.

18. We will now animate your arrow, so it looks like it’s moving towards the target. To do this we will go under the control command and drag out this block. In the white circle type in “50”. You will then place this block underneath the “stop other scripts in sprite” block.

19. You will then go under the looks command and drag out this block. In the white circle type in -10. You will then place this block inside the repeat block.

20. Test your game again. This time when you press the spacebar you should see your arrow get smaller, as if it’s moving towards the target. Once your arrow is at the target, you can tell the player how many points they have scored. For example, They could score 200 points for hitting the yellow. To add points we will first start off by going under the control command and dragging out this block. You will place the block underneath the “repeat” block.

21. You will then go under the sensing command and drag out this block. You will then press the colour button. Under colour drag the slider to “15” under saturation drag the slider to “100” under brightness drag the colour to “100”. You will then drag this block in the empty space in between “if… then”.

22. You will now go under the looks command and drag out this block. In the first white circle type in “200 points” in the second white circle type in “2”. You will then place this block inside the if… then block.

23. You will now add code blocks to make a score for the red circle. To do this we will first start off by going under the control command and dragging out this block. You will then place this block underneath the previous “if… then” block. Make sure you don’t put it inside.

24. You will then go under the sensing command and drag out this block. Click on the colour button. You will then drag the colour slider to “99” you will drag the saturation slider to “88” and you will drag the brightness slider to “93”. You will then place this block in the empty space between “if… then”.

25. You will now go under the looks command and drag out this block. In the first circle type in “100 points” in the second circle type in “2”. What this will do is when you hit the red you will get 100 points. You will then place this block inside the “if.. then” block.

26. You will now add code blocks to make a score for the blue circle. To do this you will first start off by going under the control command and dragging out this block. You will place this block underneath the previous “if… then” block. Make sure you don’t put it inside it.

27. You will then go under the sensing command and drag out this block. Click on the colour button. You will then drag the colour slider to “56” you will drag the saturation slider to “100” and then you will drag the brightness slider to “73”. You will then place this block in the empty space in between “if… then”

28. You will now go under the looks command and drag out this block. In the first circle type in “75 points” and in the second circle type in “2”. What this will do is when you hit the blue you will get 75 points. You will then place this block inside the “if.. then” block.

29. You will now add code blocks to make a score for the black circle. To do this you will first start off by going under the control command and dragging out this block. You will place this block underneath the previous “if… then” block. Make sure you don’t put it inside it.

30. You will then go under the sensing command and drag out this block. Click on the colour button. You will then drag the colour slider to “0” , you will drag the saturation slider to “0” and then you will drag the brightness slider to “0”. You will then place this block in the empty space in between “if… then”

31. You will now go under the looks command and drag out this block. In the first circle type in “50 points” and in the second circle type in 2. What this will do is when you hit the black you will get 50 points. You will then place this block inside the “if.. then” block.

32. You will now add code blocks to make a score for the white circle. To do this you will first start off by going under the control command and dragging out this block. You will place this block underneath the previous “if… then” block. Make sure you don’t put it inside it.

33. You will then go under the sensing command and drag out this block. Click on the colour button. You will then drag the colour slider to “0” , you will drag the saturation slider to “0” and then you will drag the brightness slider to “92”. You will then place this block in the empty space in between “if… then”

34. You will now go under the looks command and drag out this block. In the first circle type in “25 points” and in the second circle type in “2” What this will do is when you hit the white you will get 25 points. You will then place this block inside the “if.. then” block.

35. To end our code you will go under the events command and drag out this block. In the drop down menu select “new arrow”. You will place this block underneath the last “if… then” block.

Your code is now done!

You final code should look like this

Enjoy your game