Keepie Uppie – Scratch Video Sensing

We are going to make a game in Scratch where you will try to keep a ball up without letting it fall to the bottom of the screen. An example is shown below:

  • Start by create a new Scratch project
  • Remove the Scratch cat sprite
  • Enable ‘Video Sensing’ by clicking the blue ‘Add Extension’ button at the bottom left of the screen:

Then choose the ‘Video Sensing’ block as shown below:

If your web browser prompts you to allow the use of your webcam you will need to click ‘Allow’ for this project:

Next add a ball sprite to the stage and add the following code blocks:

This will make sure that video is switched on and that the video shows in the background. Try amending the value of 5 to 90 to see what difference it makes.

Next add some code to position the ball at the top of the screen and to allow the ball to fall:

Use the green flag to test your code.

The game would be boring if we start the ball falling from the same place each time so change the ‘x: 0’ in the previous code block so that we get a random number each time:

Test your game again by pressing the green flag.

Try increasing or decreasing the speed of the ball by changing the block from ‘-4’ to ‘-10’.

Next we will try to detect activity by the person in the video so add the following blocks inside the forever loop. You will need an ‘if‘ block, a ‘greater than‘ block, a ‘repeat‘ block and a ‘change y by‘ block:

Next we want to take some action if the ball falls all the way to the bottom of the screen. So add an ‘if’ statement to check if the ‘y’ position is less than ‘-170’:

Make the game more interesting by setting a time limit of 20 seconds for play and keeping track of the score. Add these blocks to the :

Make your game more interesting by:

  • Add multiple balls
  • Announce the score at the end of the game
  • Change the sizes of the balls using ‘set size to’
  • Change the colours of the balls

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>