- What coordinates are and how they relate to a sprite
- How to make a sprite move using user input from the mouse
- I will be able to make a sprite follow the mouse
- I will be able to make a simple game where the player collects treasure
- I will be able to add a time limit to my game
Match all of the words to their definitions on the right!
In this lesson you are going to build a Scratch game. In this game the diver collects treasure to gain points.
Finished product
You can see a preview of the finished game below:
Setup the diver, treasure and stage
Follow these steps to get started with your game:
- Open Scratch on your computer
- Name your Scratch project as: Diving Game
- Delete your Cat sprite from the game
- Add the Diver1 sprite to your game
- Add the Star sprite to your game
- Change your backdrop to the Underwater 1 backdrop
- Create a variable called points for all sprites
- Create a variable called time for all sprites
- Save your project
Add mouse controls to your character
In the previous lesson we looked at how to make our cat sprite move using the keyboard. For our diver to move, we need to add some blocks to make the diver follow the mouse.
What happens to the diver when he gets to the mouse?
To fix the issue where the diver starts to flash backwards and forwards, change your code to:
Without this code, the driver would constantly flash backwards and forwards when the mouse cursor goes over it.
Collecting stars
Select your Star and add the following blocks:
Make the points variable increase by 1 and put it inside the if block. Remember to set the points to 0 at the start as shown below:
Moving the star
Each time the player gets a star we want the star to appear in another location on the scene.
To do this, we are going to make the star go to a random position on the scene. Find the following three blocks and then add them after the hide block.
Your blocks should now look like the blocks following.
Duplicate our stars
Let's make more than one star to collect. To copy all the code we have put in and keep it exactly the same, we need to duplicate the star:
Do this 4 times to get to a total of 5 stars.
Position our sprites
Now that you have created your stars, position them similar to below by clicking on them in the stage and dragging them to where they are to go.
Adding a time limit
Go back to the diver sprite.
Follow these steps to create a timer in your game:
- Go back to the diver sprite.
- Create a variable to store time.
- Add the following blocks to your diver:
-
A timer is something that repeats over and over for a certain amount of time. This means we can use a loop in Scratch to make a timer.
To do this, add the following blocks below what you just added:
This code is make a timer that ticks every one second removing 1 from the time variable.
-
Now we need to make the game stop when the timer runs out. Change your code so that it looks like:
What this does is checks if the player has not got 10 points and then tells them they have run out of time.
Winning the game
To win the game, we should have something similar to the previous game. By including a forever around our points check, we can constantly be checking to see how many points the player has and stop the game when they get a certain number. Add the following blocks to our diver:
-
1
Upload your screenshot below:
-
2
What would happen if you didn't include the wait 1 seconds block in the timer code as shown below?
-
3
The code for a star is shown below. It's not been correctly coded.
It's noted that the show block is in the wrong place. Where should it go to fix this program?
-
4
What would happen if we used the first code shown below rather than the second code?
-
5
Why is a forever block used around the following code?
-
6
How well do think you completed this task?
-
7
What parts of this task, if any, did you struggle with?
- Add an item that if picked up takes away a point.
-
Try to animate your stars when they are collected. You could use the following blocks instead of just using the hide block: