You are currently viewing Scratch Learning: Building an Underwater Chase Game with Diver and Shark 

Scratch Learning: Building an Underwater Chase Game with Diver and Shark 

Our next game is a Chase game where one character will try to protect itself from another character that is following it. 

So our first step is adding in our characters. For this scenario, we choose a diver and a shark with our background as the underwater scene. 

Now we need to code our diver to move according to us. 

We want the diver to move when we press the direction keys. To do so, we first take a “when space key pressed” Event block and change the key to “down arrow key”. Then we add in a “move 10 steps” as well as a “point in direction 180” Motion block. This will change the direction the diver is pointing down when we press the down arrow key and move the diver 10 steps downwards. We change the direction by clicking the textbox in the “point in direction” block and dragging the arrow to the desired angle. 

Similarly, we make the code for the rest of the direction arrows. We keep the number of steps the same but change the direction each time. For the left arrow, the direction should be “-90”, “0” for the up arrow, and “90” for the right arrow. 

Now we need to code the shark. The shark needs to keep moving towards the diver. So we first take the “when green flag clicked” block, add a “say ___ for 2 seconds” Looks block to make it more appealing, and set its starting position by using the “go to x:__ y:__” block and setting x to “-175” and y to “145”. 

The rest of our code should be continuous so we add a “forever” block, a “move 2 steps” and a “point towards Diver1” block. 

Next, we put in the code for what happens if a shark touches a diver. We put in an “if__ then” condition block from Control and input the condition “touching Diver1?”. Once the condition is true, we will make the shark send out a message to diver1 to let it know that it has been caught. We do this by adding the “broadcast message1” Events block. Then we join a “say MUNCH!!” Looks block and a “stop all” Control block. Change it from “all” to “this script”. 

And just to make the game more attractive, we are going to have the sound of ocean waves playing forever. We take a new “when green flag clicked” and “forever” block and join a “play sound water until done” from Sound.

For the last part, we have our diver receive the message sent by the shark. We do this by using the “when I receive message1” Event block and the “say AAAAHHHHH” Looks block. You can also add in a Sound block for a scream. 

Leave a Reply