Squeakland Bouncer

This week we will make a ball move around the screen, but stay inside four invisible 'walls'. We will create a script that loops, making the balls move left/right & up/down in steps of 20 pixels (screen dots).

A variable is a word that represents a number. We will create two variables called xstep and ystep for the distance the ball should move along the x axis and up the y axis.

At each step the script will:

  • Add xstep to the ball's x
  • Add ystep to the ball's y
  • If we've reached the 'right' wall, change xstep to +20
  • If we've reached the 'left' wall, change xstep to -20
  • If we've reached the 'top' wall, change ystep to -20
  • If we've reached the 'bottom' wall, change ystep to +20

This means when we're adding '20' the ball moves right/up, when we're adding -20 we're moving left/down.

Build the script

1. Open the 'Supplies' tab and drag an ellipse (oval) onto the screen.

2. Hover over the ellipse to make the handles appear

3. Change its name to 'ball'

4. Open a viewer for 'ball'

5. Select the 'Geometry' menu ('geometry' means shape) and set ball's width and length to 40

6. Drag out a script, call it 'bounce'

7. Add 4 yellow 'test' boxes into the script

8. Click the small 'v' button at the top of ball's viewer to create a 'variable' (a word that represents a number that can be changed). Call it 'xstep'. Create another called 'ystep'.

9. Now build the following script by dragging each part into the test boxes:

Test the script

1. Press the clock to 'run' the script

2. Stop the script, select the 'Pen' menu and turn on the pen. Run the script.

3. Stop the script, change the colour. Move the ball and start the script again.

4. Try changing the numbers in the script. What happens?


Related pages: Squeakland

Category: ICT

Author: Mr Kershaw

http://bradfordchristianschool.com/SqueaklandBouncer

Bradford Christian School, Livingstone Road, Bolton Woods, Bradford BD2 1BT Tel: 01274 532649   Fax: 01274 595819
school office | webmaster@bradfordchristianschool.com