In this activity, learners create a game in Scratch in which they have to save the shark by eating fish and avoiding rubbish. The project explores relevant environmental themes such as sharks’ food sources and the negative impact of plastic in the ocean.
Although it has a serious theme, Save the Shark is a fun project that introduces learners to game building while also educating them about the environment. Using step-by-step instructions, learners are introduced to key computing concepts such as selection, variables, and random numbers.
Age range: 7–10 years
Year group: Years 4–6
Lesson type: Visual/block-based coding
A computer or tablet capable of running Scratch
Scratch 3 (either online or offline)
How to use random numbers to change costumes
How to generate and delete clones
How to use random numbers to alter the behaviour of clones
Activity 1: Move the shark
In this step you will learn how to use code to control the motion of a shark on the screen using the mouse. If you are working online, open the starter project in Scratch. If you are working offline, open the project starter file in the Scratch offline editor.
In the starter project, you should see a shark sprite against an underwater background. When the green flag is clicked, the shark should start at the bottom of the screen.
To make this project mobile-friendly, you’re going to use the location of the cursor when the left mouse button is pressed, or when a finger touches the screen, to control the movement of the shark.
Add a forever loop to your script so that your program can constantly detect when the left mouse button is clicked, then use an if... then block to detect if mouse down — see figure 1.
When the mouse is clicked, if the mouse x position of the cursor is less than the x position of the sprite, then the sprite should change x by -10, so that it moves left. Add the following blocks, as shown in figure 2.
Click on the green flag to run the program and test that the shark does move to the left.
If the mouse x position of the cursor is greater than the x position of the sprite, then the sprite should change x by 10, so that it moves to the right. Add the following blocks, as shown in figure 3.
Click on the green flag to run the program and test that the shark does move to the right.
Activity 2: Plastic waste
You should see a sprite that looks like a plastic bottle in your sprites pane beneath the stage. This sprite has four costumes: a bottle, a wrapper, a bag, and a can holder.
When the flag is clicked, this sprite needs to move to the top of the screen and then hide itself. Add the code as shown in figure 4.
The plastic sprite should now randomly generate clones of itself. See figure 5.
When a clone is created, it should show itself, pick a random costume, and then move to a random x position. Add the code shown in figure 6 as a new script.
You want the speed at which the plastic moves towards the bottom of the screen to be random, so create a new variable called speed.
Set the speed to be a random number, and then move the clone down the stage using the speed variable. See figure 7.
Run your game, and you should see plastic waste falling from random positions and at random speeds from the top of the screen. The problem is that the waste accumulates at the bottom of the screen, and stays there. Add blocks to detect when the plastic sprite touches the bottom of the screen, and then deletes itself. See figure 8.
Activity 3: Shark Health
In this step, you are going to include health points using a variable. The health of the shark will reduce if it accidentally eats plastic waste.
Create a new variable called health.
On the shark sprite, when the game starts, the shark’s health should be set to 20, and then when the health gets below 0, the game should end. See figure 9.
Back on the plastic sprite, add some code to reduce the shark’s health if it accidentally eats any of the plastic. See figure 10.
Run the program again to test that the health of the shark reduces if it eats plastic.
Activity 4: Feed the shark
Now, when you play the game, the shark needs to avoid the plastic, or the game will end because the shark’s health has decreased. In this step, you’ll add fish that the shark can eat in order to increase its health.
Add the fish sprite to your project. The code for the fish sprite is almost identical to the code for the plastic sprite. Drag and drop the three scripts from the plastic sprite onto the fish sprite in the sprites pane.
Now you can edit the code that reduces the shark’s health, so that it increases the health instead. See figure 11.
Run the program again to test that the health of the shark increases if it eats fish.
More advanced coders could add different fish that give the shark increased health, and adjust which plastics hurt the shark the most. Less advanced coders could be provided with a more complete starter project with a few blocks missing.
For further information and more projects visit projects.raspberrypi.org