Posted on

Scratch Coding – Life Raft Challenge

The goal of this game is to move the life raft to the main boat, but beware there are obstacles all around.

Step 1: Setup

Start by adding a new life raft sprite:

We need a backdrop that will contain the walls and rocks:

Step 2: Boat Movement

We want to have our boat follow the direction of the mouse pointer, this way we can glide our boat with our mouse.

We can use the following block to help us:

Since we always want to be moving towards the mouse pointer while the game is on, we will need to place this in a forever block.

Question: What happens if we have the following code?

To fix this, we need to make sure that the mouse pointer is at least 5 pixels away from the boat. (we can use an if statement).

In our main loop we can also test to see if the boat has hit the rocks. We can use the colour detection blocks to determine this:

If we have hit the rocks, we need to show our crashed costume for 1 second and move the boat back to the starting spot.

Step 3: Sailboat Rescue

We need to add our rescue boat to the game:

The scripts for this boat has to be always looking to see if the life raft has touched it.

We will need a forever block and an if block that uses the sensing blocks.

If we touch the boat, we can stop the background timer by calling the stop all block:

Step 4: Background

We should add a background timer to keep track of how long it takes to complete the maze.

We need to add a variable called ‘timer’.

In our forever loop we will change this value by 0.5, we will also add a wait block for the same amount of time.

If we double click on the variable on the screen, we can make it smaller:

Extras:

Add new sprites that act to slow or speed up your boat.

Since we can’t change the movement of the boat sprite from these new obstacles, we must broadcast a message to our boat sprite:

Then our boat will listen for these events:

Create sprites and broadcast messages for:

  • Pause (this wastes time)
  • Current Left (move the boat to the left)
  • Current Right (move the boat to the right)
  • Speed up (move the boat forward, with the move steps block set to a larger number).

More:

  • Use a list to store the high scores.
  • Use a pen to create a line behind the boat just like the wash from a boat motor.