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.
Posted on

Scratch Coding – Race Car

Your goal is to create a race track that you can race your car around. Mine looks like this:

Notice how I have a nice red line for the end and my road is all one colour.

You will need to create your own road and car.

The very basic start to your game will use the following code:

We now need to add some code to check to see if the car has moved off the road.

Posted on

Scratch Coding – Fish Music

We are going to create a school of sing fish today.

When we click on the fish we are going to animate them and have them make some sounds.

If I pick one of my fish, I can use the following blocks:

I’ve used the ‘play note’ block to make a sound. The ‘next costume’ has also been added to make the fish come to life.

We can add a number of different fish with different notes and timings, then we can click through each fish and put together some cool tunes.

Instructions for the player

It might not be clear to users of our program that they need to click on each fish to make them sing, so we are going to add a message to the screen. To do this we are going to create a new sprite and add some text to it with the text tool:

We only want to show this to the player for the first three seconds after the green flag is pressed:

Be sure to use some loops on some fish:

Explore the sound library

Scratch has a number of cool sounds that can be added to our fish, check out some of these:

Now we can use both the basic notes and the more complex music that we added to our sprites.

Posted on

Scratch Coding – Angry Birds

Today we are going to build a simple Angry Birds game where we shoot a bird up to hit a nasty pig.

The first thing we need to do is create a new sprite for our nice red bird.

Normally we use the ‘Choose a sprite from the library’ button, but the library doesn’t contain the nice bird picture that we want to use. Instead we are going to use the ‘upload sprite from file’ button.

Once we click on this, we need to find our file. Do the same thing for the green pig. We should end up with two nice sprites:

Now that we have our sprites setup, we can start thinking about how the game should work.

Some ideas of the game might include:

  • Make sure the Angry bird starts in the correct spot
  • Make sure the Green Pig starts in a different spot each time
  • Ask the player the angle that the angry bird should be fire
  • Fire the angry bird off at the angle the player gave
  • Keep score of how many times the bird hit the green pig

The range of angles that we will use, looks like this:

Use this image to help play the game by placing it behind your Angry Bird sprite.

To start our game, we need to make sure that both the bird and the pig start in the correct spots.

On the Angry Bird:

Let’s add the ‘Green Flag Hat Block’ so that we can move the bird when the game starts:

Pick a good starting spot for your bird, I’ve chosen -175, -95.

Ask the player for an angle

Next we want to ask the player which angle we should use to shoot our Angry Bird:

We can then use the answer to turn the bird to the number given by the player.

Making the bird move

We would like our bird to move until it either hits the edge of the screen or if it hits the Pig. To do this we can use the ‘repeat until block’.

The code that we add into this block will run all the time while the bird doesn’t touch either the edge of the screen or the pig. We do however want our bird to move, so let’s add some steps to this code.

Test it out. We should see that the bird will stop either at the pig or on the side of the screen.

On the Pig:

Make the pig move to a random spot

We want to make the angle that the bird needs to fly different each time the game is played. We don’t really want to move the pig closer to the bird, we just want it to be higher or lower on the screen. This is the Y Axis, so when we pick a random spot, we will not change the X axis (across the screen).

Test out the game now. Does it work OK?

Adding a score:

Now that we have our game almost working, we would like to keep score. To add scoring to our game, we need to create a variable that the computer can use to store the score.

Once the variable has been created, we should have some new blocks:

We can now change the code on our Angry Bird sprite to check to see if the bird has touched the pig.

Notice that I’ve also added the block to point in the direction (0) (Up).

Test your game out. How many pigs can your angry bird hit?