Scratch Hungry Shark Game Step-by-Step Instructions Introduction: In this unit we will be learning to create a game where the hungry shark swims around the screen guided by your mouse. Each time he eats a fish he will get points, but watch out for the poisonous crab! In Scratch, the program that controls the characters is called the script. The characters in the game are called the sprites and the stage is where the action takes place, like a real stage in a play! 1
Step One create a background First cut the cat sprite using the scissors. Then click on the Stage and click on the Backgrounds tab in the middle of the screen. Import the Underwater background from the nature folder or create your own using the Paint Editor. Use the scissor tool to cut the cat sprite Select the stage and click on the Backgrounds tab Click on import and select the underwater background from the Nature folder Step Two create a new sprite Click on Choose a new sprite from file to open the resources. Double click on the Animals folder and select Shark 1-a. Click ok to choose. Now we need to animate the Shark. We will achieve this by giving the shark more than one costume to wear. Choose a new sprite from file 2
Step Three add more costumes and write a script for your shark The script contains the instructions that tell the shark what to do. While Sprite 1 is still selected, click on the Costumes tab to import another costume, then select Shark1-b. Your sprite should now have two costumes in his wardrobe. Costumes tab The blue box indicates that this is the sprite you are working on. Make sure you have imported two costumes NOT two separate Sprites! Then write a script that looks like this: Click here to keep your shark swimming the right way up! Shrink your sprite with this tool Drag the pieces of script from here 3
Step Four debugging your project If your project doesn t work first time then it is likely there are errors known as glitches or bugs in your script that are preventing it from working correctly. Check carefully that you have followed all the instructions exactly, as even tiny mistakes can cause problems. Don t give up though, debugging is a job that all computer programmers have to do! Step Five adding animated fish To make the game fun you need to add a purpose. In this game our shark is going to collect points by eating up as many fish as he can. First we re going to start by adding some new sprites just like we did in Step Two. Choose fish 1-a from the animals folder Import fish 1-b as his second costume (see Step Three) Shrink the fish down to an appropriate size (see image for Step Three) Write a script that looks like this: Is your fish swimming backwards and forwards across the screen? Is he animated like the shark? Is he swimming the right way up? (See image for Step Three) Step Six creating a variable To make our game exciting we need to add a scoring system. To do this we need to create a variable to hold the scoring information. Click on the variables tab Select make a variable Create a variable for all sprites called score 4
Step Seven adding the variable to the script Now we want our shark to eat our fish and get a point each time he does that. To achieve this we are going to have to add some information to our script. We are going to tell the fish that if he touches the shark then he should hide for five seconds, add a point to the score and then reappear again. Change your fish script so that it looks like this: In the script pictured here the variable changes the score by 1 but you can change this value if you wish; you can also change how long the fish hides for. Step Eight adding more fish. To make the game more fun and exciting try adding more animated fish e.g. Starfish 1-a with costume 1-b. The code should be exactly the same as for fish 1-a (repeat Steps Five and Seven, you don t need to create a new variable again). Can you change the speed of your starfish in the move block so that he moves more quickly? Can you change how many points he scores as well? 5
Step Nine adding a poisonous crab. To make our game harder, we are going to add a poisonous crab. If the crab touches the shark he is going to take away 1 point. Import crab 1-a with crab 1-b as his second costume (see Step Two if you can t remember how to do this) Shrink the crab down to the right size (see the image in Step Three) Check he is swimming the right way up (see image for Step Three) Write a script that looks like the one below Import the sounds from the circled area below 6
Step Ten setting the coordinates and game reset Have you noticed that when you move your mouse around the shark game, the coordinates change at the bottom of the screen? This facility allows us to decide where on the screen the sprites will go at the start of the game. Finally, to finish our game off we are going to add a reset function. Add the following blocks to your shark script. Can you set different coordinates for all your sprites? It s up to you to decide where to position them at the start of the game. Extension Tasks Well done, you have completed your mission! Now it s time to make the game your own. Try some of the following challenges: Can you paint your own sprite and add it to the game? (Try paint sprite instead of import sprite) Can you add some music at the start of your game? Can you make some of your characters speak/make sounds, or change the way they look? Can you work out what the pen menu does when you add some of the blocks to your scripts? Can you change the scene in your game by adding a script to the stage? Finally, if you have created your own scratch account at home, try uploading your finished game to the scratch website (go to share in the main tool bar to do this). 7