Scratch Game
Normal
60 mins
390 points
What you need:
  • Computer/laptop

Diver Game

In this game you dive underwater to collect starfish but be careful of the shark chasing you!

This code along has finished! ⌚

You can watch it back by playing the video!

The code along is open for everyone to join in but if you would like to earn the points and badges please join our club!

1 - Create a new Scratch project

Create a new Scratch project and delete the cat sprite.

https://scratch.mit.edu

In this game there will be 3 sprites

  1. a diver that you will control with your mouse
  2. starfish that will appear in a random position and you will collect
  3. a shark that will slowly follow and try and catch you

3 - Add and program the Diver1 sprite

Add the Diver1 sprite from the sprite library. We are going to program the diver to always point towards your mouse pointer and move towards it. This is how you will control where the diver swims to.

Add the following code to the Diver1 sprite.

when green flag clicked go to x (150) y (0) set size to (50) % forever point towards (mouse-pointer v) move (4) steps end




2 - Add the Underwater 1 backdrop

Add the Underwater 1 backdrop to the project.


4 - Add the Starfish sprite

Now add the Starfish sprite to your project.


5 - Hide the Starfish and create a clone

At the start of the game the starfish will appear in a random position and each time you catch a starfish a new one will appear somewhere else.

Add the following code to the Starfish sprite to change it's size, hide it and create a copy of it.

when green flag clicked set size to (30) % hide create clone of (myself v)

We will program what to do when it's copied in the next step.


6 - Program the Starfish

Now let's program what the starfish should do when a copy (or a clone) of it is created.

When the copy is created we will program it to:

  1. go to a random position
  2. make it appear
  3. using the sense block touching [Diver1] ? keep checking if it is touching the Diver1 sprite and if it is create a new copy of it and delete this one

Add the following code to the Starfish sprite.

when I start as a clone go to (random position v) show forever if < touching [Diver1 v] ? > then create clone of (myself v)// create a new copy delete this clone // delete this one end end



7 - Add the Shark 2 sprite

Let's add some danger into the game!

Add the Shark 2 sprite from the library and the following code to make the shark appear in a random position and then start chasing the diver.

when green flag clicked set size to (50) % go to (random position v) forever point towards (Diver1 v) move (1) steps // slower than the diver end



8 - Game Over

Finally let's add some code the stop the game if the shark catches the diver. Again we will use the block touching [Diver1] ? to sense that the shark sprite is touching the diver sprite and if it is then we will stop all the code so that the game is over.

Add the following new code to the Shark 2 sprite underneath the move 1 steps block.

when green flag clicked set size to (50) % go to (random position v) forever point towards (Diver1 v) move (1) steps // add new code under here if < touching [Diver1 v] ? > then stop [all v] end end



9 - Challenge!

As an extra challenge can you add some extra code to keep score of how many starfish you collect before the shark catches you? 

What do you need to create and where do you add the new code?

see answer

Create a new variable called 'score'.

Add the following code to the Starfish sprite.

when green flag clicked set [score v] to (0) // start at 0 when I start as a clone go to (random position v) show forever if < touching [Diver1 v] ? > then change [score v] by (1) // add this block here create clone of (myself v) delete this clone end end


Join our club 😃

Create your profile, earn points & badges and learn how to code!

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more