Scratch game exercise 119

Select level

In this exercise a cat is chased by a bat, and must avoid being spat on to retain lives!

You will allow the user to select the game difficulty level.

 

Complete these steps ..

 

1. Create a new game, select the stage and then click the background tab. Click "edit" and fill the stage with a bright colour. We have chosen yellow.

 

 

2. Add these scripts to the stage ..

Notice how we are broadcasting "prepare game" instead of "begin game". We will broadcast "begin game" after we the player has chosen a difficulty level.

 

3. Download and save these sprites and then add them to your game ..

 

 

3. Select the "Select level" sprite and create these variables ("for all sprites") ..

We only need the "Cat lives" variable visible on the stage so un-tick all the others.

Position the "Cat lives" variable at the edge of the stage ..

 

 

4. Select the "Select level" sprite.

When a player starts the game, "prepare game" is broadcast. Let's add a script to the "Select level" sprite to ask the player to chose a difficulty level, 1, 2 or 3.

Notice how the script puts their answer into the "difficulty level" variable and then broadcasts "initialise variables".

This script also tells the player to "Enter 1, 2 or 3" if they enter anything other than "1", "2" or "3".

 

 

5. "Initialise" means "set the starting value of something". In this case it is our variables. Their values will depend on the level chosen and thus set the games difficulty.

Add this script ..

Notice how the final script step broadcasts "begin game".

Finally add this simple script to hide the "Select level" sprite when the game begins.

 

 

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

Use File>Save as to save your game. Name it "Select level".

 

 

7. Select the cat sprite. Re-name the sprite "Cat" and then, click the direction button to make sure the Cat can only face left-right ..

 

Now add the first script to set its size and position on the stage ..

 

 

8. Add the next cat script. We will allow the cat to move faster when a easier level is selected (eg 1), and slower when a harder level is selected (eg 3) ..

Look at step 5 of this exercise to see the cat speeds for the different levels.

 

9. Time to add the cat lives script ..

 

 

10. Finally, add this script to hide the Cat sprite until the game begins

 

 

11. Press the "B" key to test your game. Use the arrow keys to move the cat. Press "E" to end when you are done.

Use File>Save to re-save your game.

 

 

12. Now lets script the Bat which will attack the cat (by chasing and spitting at it!). Select the "Bat" sprite and set it to "only face left-right" and then add the scripts ..

Finally, add this script to hide the Bat sprite until the game begins ..

 

 

13. Now select the "Bat spit" sprite and add the scripts ..

Notice how the the "bat spit wait time" and "bat spit speed" use variables which will change depending on the level.

 

Finally, add this script to hide the "Bat spit" sprite until the game begins ..

 

 

14. Press the "B" key to test your game. Use the arrow keys to move the cat. Press "E" to end when you are done.

Use File>Save to re-save your game.

 

 

15. Well done. You've finished. Can you add levels to one of your games?