Scratch exercise 13

Random stage location

In this tutorial you will learn how to make the cat jump to a random location on the stage.

 

NOTE: You can use any version of Scratch.

 

Complete these steps ..

 

1. Open Scratch, OR create a new game (from the top menu choose "File>New").

 

 

2. Select the cat sprite under the stage and re-name it "Cat" ..

 

If you are using Scratch 1.4 you can move your mouse-pointer to the centre of the stage. Look in the bottom right corner of the stage and try to get x:0 and y:0. This is the center of the stage. Move your mouse-pointer around slowly and watch the x and y numbers change.

 

 

4. We are going to start by making the cat appear somewhere along the bottom edge of the stage. The stage is 480 pixels wide (x: -240 to 240).

Add this code to the Cat sprite ..

 

Press the "B" key to begin your game. Every time your press the "B" key the cat will jump to a random location along the bottom of the screen.

 

 

4. Now let's make the cat appear somewhere along the right edge of the stage.

Drag the blue "go to" code away from the "when b key pressed" script block but don't delete it.

 

The stage is 360 pixels high (y: -180 to 180).

Add this code to the Cat sprite ..

 

Press the "B" key to begin your game. Every time your press the "B" key the cat will jump to a random location along the right edge of the screen.

 

 

5. Let's make the cat jump to a random location anywhere on the stage.

 

Combine the code you have created to make this code ..

 

 

6. Use the File menu to save your game. Name it "Random stage location v1" ..

 

 

7. Well done, you've finished this tutorial.