- How to use communication between objects (sprites) in Scratch
- How to use logic in Scratch
- I will be able to make a game in Scratch using a series of instructions
In this lesson we are going to build upon what we did in lesson 4 and add in a shark. This will make the game more of a challenge. If you have finished lesson 4, you can open that to give you a head start. You can find lesson 4 here.
Finished product
You can see a preview of the finished game below:
Setup the diver, treasure and stage
- Delete the cat sprite
- Add a diver sprite
- Add a shark sprite
- Set the backdrop to an underwater backdrop
- Create two variables, one called lives and one called points
Resize your sprites
Resize both the shark and the diver to about 50% to make sure that it's not too big and not too small.
Setting up the diver
Once again, the diver is going to follow the mouse. Add the following blocks to the diver make the diver follow the mouse:
Set up the shark
The shark's purpose is to catch the diver. In your shark sprite, add the following blocks:
Lives
The diver will need lives and when they reach 0 the player loses.
To do this, add the following blocks to your diver, remembering to use the variable called lives:
The go to x: 138 y: 104 block is very important since it moves the diver away from the shark when they are touching it and prevents the shark removing all lives in one go.
The broadcast bite and wait part is also very important to ensure that the diver also tells the shark to move away when he is bitten. This broadcast feature is a really useful part of Scratch that allows sprites (also known as objects in computer programming) to communicate.
Shark code
On the shark there needs to be some code that lets the player know they have been bitten by the shark. Add the code blocks on the right to the shark to make a bite sound when the shark touches the diver and to move the shark when he bites the diver:
Adding stars
Much like in lesson 5, we are going to add stars. The code blocks for our starts will be the same as in that lesson but with an extra bit added that makes the blocks go up to the top:
Adding a win condition to the diver
Now we need to allow our diver to win by getting 10 points. To do this, add this sequence of blocks to your diver sprite:
Adding a loss condition to the diver
Now we need to make it possible for our player to lose. To do this, add the following sequence to your diver:
Duplicate the stars
Duplicate your stars so you have multiple stars in the game, say 5 of them.
-
1
Upload your screenshot below:
-
2
What does including the not block do in the code shown below?
-
3
How well do think you completed this task?
-
4
What parts of this task, if any, did you struggle with?
- Add in a rare item that the player can collect that would give them a live back
- Advanced: Create an item that would allow the player to move faster (you will need a variable that stores the number of steps the player is to move)