Scratch exercise 76

Gun select - from an inventory

In this tutorial you will script algorithms that allow a player to select a gun for a character, from an inventory which they can hide or show.

Complete these steps ..


1. Create a new game file.


2. Click on the stage and add these scripts ..


3. Create these variables (for all sprites) ..

Hide them on the stage.

4. Re-name the cat "Soldier" and add these scripts ..


5. Paint a new button sprite that the player will use to hide and show the gun inventory. Give it 2 costumes "Show guns" and "Hide guns" ..

Add these scripts to it ..


Note that the "gun select y-pos" variable is used to re-position the guns in the inventory (bottom of screen) when they are not being used.


6. Save your game.


7. Download, save and import each of these individual sprites/costumes ..




Name the sprites "AK47", "Rifle" and "Pistol".


8. Add these scripts to the AK47 ..


9. Add these scripts to the rifle ..


10. Add these scripts to the Pistol ..


11. Save your game again.


12. Paint a simple text sprite in 18pt with the words "Click gun to select" ..

Place it just above the guns on the stage and then add these scripts ..


13. You're done! Press "B" or click the Green Flag to test your game.


14. Can you improve it?