Scratch Silver III
Scratch Silver II
SCRATCH SILVER I
SCRATCH GOLD III
1 of 3

2.05 The asteroids puzzle

In this step, you will create the most challenging puzzle. You will create a puzzle to destroy dangerous asteroids.

You will need a crosshair that you can use to target the asteroids.

Paint a new sprite called crosshair. An example is shown below, using a circle and two lines. Make the circle solid initially and then adjust its fill to transparent, once you have it sized and positioned.

A crosshair consisting of a small red circle with bisecting diagonal lines, centred in the canvas.

Resize your crosshair sprite if you need to.

Tip: You can zoom in on the paint editor, using the + and  symbols, to make positioning easier, especially if you are on a mobile or tablet device.

The crosshair will follow the mouse, but it should only be visible through the window into space.

Use the following blocks so that the crosshair follows the mouse-pointer.

The crosshair sprite.

Test: Click the green flag and make sure that the crosshair follows the mouse-pointer.

You can use an if block to test if the crosshair is touching the port sprite, so that it is hidden when it is not touching it.

Add a test, to make sure that the crosshair is touching the port.

The crosshair sprite.

Test: Click the green flag and make sure that the crosshair hides when it is not touching the port.

You might notice that the crosshair appears at the very edge of the port and so appears to be inside the spaceship. This can be fixed by checking it’s not touching a colour of the backdrop.

Add an or block to the if block. The second condition is if the crosshair is touching the green colour that surrounds the port.

Tip: As the crosshair follows the mouse-pointer, make sure you stop your project before using the colour picker.

Now it’s time to create the asteroids.

Find a Rocks sprite and add it to your project. Resize the sprite so that it is not too big.

You may have seen how my blocks help keep code organised in the Nature rover project.

My blocks also help by making it so you don’t have to write the same code over and over again. You can use my blocks for the Rocks to position them in the spaceship’s port.

Create a new block and call it go to position. The starting position can be anywhere on the screen.

The Rocks sprite.

The Rocks sprite needs to keep finding a random position until it is touching the port and not touching the edge of the port. This is similar to the code you used on the crosshair, but this time you will use an and block.

Add a repeat until and an and block to make sure that the Rocks keep moving until they are in the correct position.

Test: Click on your my blocks definition and you should see the rock move randomly around the screen, until it stops in the port.

The Rocks need to be hidden from view as they move, but if they are hidden, they won’t be touching the port, so a ghost effect can be used to make them invisible.

Set the ghost effect on the Rocks to 100 while the sprite is moving, and then clear the graphical effect.

The last part is similar to the other puzzles. Using a variable called asteroids, count how often the crosshair touches the Rocks. Each time it does, the asteroid variable increases and the Rocks move to a new position. This should only work if your character is at the chair though.

On your character sprite, create a new variable called at chair, and set it to true when the character is touching the chair and false when they are not.

Add the following blocks to the Rocks sprite to set when the task is complete.

The Rocks sprite.

Use another and block in an if block to check that the crosshair is touching the rock and that the at chair variable is true.

The Rocks sprite.

If the condition has been met, then the asteroids variable can be increased by 1 and the my block can be called again so the Rocks move to a new position.

The last thing to do is tell the player about the task. This can be done on the port sprite.

Add blocks to tell the player how many asteroids have been destroyed.

Test: Move your character close to the chair, then move the crosshair around and try to destroy some asteroids. You can then adjust any of the values in your code that you need to in order to make it work well for your sprite sizes.

×
×

Cart