Scratch game making tutorial 122

Island hop

In this tutorial you will make a game in which you must collect treasure. But beware the shark, he will steal your treasure!

 

Complete these steps ..

 

1. Download and save this stage background image ..

 

 

2. Create a new game, then select the stage, and then click the background tab. Import the sea-background.bmp image ..

Now, delete the white one.

 

 

3. Add these scripts to the stage ..

 

 

4. We need 2 variables for this game. One variable to display how many treasure chests the player has collected and one to set the size of the islands.

Create these variables ("for all sprites") ..

Make sure the "island size" variable is hidden on the stage (un-ticked). Locate the "Treasure score" variable in the corner of the stage ..

 

 

5. Add this script to the stage ..

Later, you will be able to experiment with the size of the islands. Smaller island will make the game more difficult.

 

 

6. Download and save these sprites ..

 

 

7. Now click the "choose new sprite from file" button under the stage and import them one by one ..

 

 

 

8. Select the cat sprite and re-name it "Cat".

Click on the "only face left-right" button ..

 

Now add these scripts so it is ready when the game begins ..

 

Now add this script to control the movement of the cat ..

 

 

9. Now, press the "B" key to test your game. The cat should follow your mouse-pointer. Press "E" to end when you are done.

Use "File>Save as" to save your game. Name it "Island hop".

 

 

10. Before we finish the cat scripts we must script some of the other sprites.

Let's script the islands. The cat will be safe from the shark when he stands on one. We'll make them appear at random times and places around the stage.

 

Select "island 1" then click on the square button to prevent the island from rotating ..

Do this for "island 2", "island 3" and "island 4".

 

Select "island 1" and add the first script ..

We will use the ghost effect to make the island fade in and out of view. When the ghost effect is at 100% the island will be completely invisible.

Note also that we have set the size of "island 1" to the "island size" variable. If you remember, we set "island size" to 100% in a stage script. Go and check it now ..

 

 

11. Let's add the second island script. This script will make the island wait for a random time (0 to 10 seconds), move to a random position on the stage, and then fade in, wait for 10 seconds, and fade out again ..

 

 

12. Copy the "island 1" scripts to "island 2", "island 3", and "island 4". Now, press the "B" key to test your game. The cat should follow your mouse-pointer and the island's should randomly appear and disappear. Press "E" to end when you are done.

Use "File>Save" to re-save your game.

 

 

13. There is a problem with the islands. Sometimes they appear on top of one another. Let's create a script to make them separate away when they touch.

Add this script to "island 1" ..

Now copy the script to "island 2" and then change touching scripts to "island 1", "island 3" and "island 4" ..

Copy the script to "island 3" and do the same ..

And finally "island 4" ..

Now, press the "B" key to test your game. When the island touch they should move apart. Press "E" to end when you are done.

Use "File>Save" to re-save your game.

 

 

14. Although the cat follows the mouse-pointer, he only glides. It would be good if he walks when he is on land and swims when he is in the sea.

Select the cat and then switch to the costumes tab. You will see that the cat has 4 costumes, 2 for walking and 2 for swimming ..

 

Switch to the scripts tab and add this script ..

 

Now, press the "B" key to test your game. The cat should walk on the islands and swim in the sea. Press "E" to end when you are done.

Use "File>Save" to re-save your game.

 

 

15. Select the "treasure" sprite. Let's make it appear randomly like the islands. Add the first script ..

 

Now add the second script ..

 

Now, press the "B" key to test your game. The treasure should appear at random places on the stage. Press "E" to end when you are done.

 

 

16. It would be cool if the treasure floated in the sea and stood on the land.

Switch to the costume tab and you will see we already have costumes prepared ..

 

Switch back to the scripts tab and add this script ..

 

Now, press the "B" key to test your game. The treasure costumes should change depending on if it is on land or in the sea. Press "E" to end when you are done.

Use "File>Save" to re-save your game.

 

 

17. We have one final script for the "treasure" sprite. When the cat touches it we want the "treasure score" to increase and the treasure should disappear for a while.

Add this script ..

Now, press the "B" key to test your game. Move the cat to touch the treasure when it appears. Press "E" to end when you are done.

 

 

18. The game needs an enemy. Select the "shark" sprite. This sprite will chase the cat and steal treasures from it.

Set the sprite to "only face left-right" then add this script ..

 

We want the shark to chase the cat but to turn away when it touches an island. Add this script ..

 

Finally, we want the "treasure score" to decrease when the shark catches the cat, but only when the score is greater then 0.

Add this script ..

 

 

19. Use "File>Save" to re-save your game. Well done. You've finished.

Press the "B" key to test your game. Press "E" to end when you are done.

 

 

20. Can you make this game better? What about adding your own ideas and mods?