Scratch Game
Hard
60 mins
370 points
What you need:
  • Computer/laptop

Keepy Ups

In this Scratch game we will use the video sensing blocks to interact and play a game where we have to keep multiple footballs in the air!

To do this lesson your computer must have a camera on it.

This code along has finished! ⌚

You can watch it back by playing the video!

The code along is open for everyone to join in but if you would like to earn the points and badges please join our club!

1 - Create a new Scratch project

Create a new Scratch project and delete the cat sprite.

https://scratch.mit.edu

2 - Add the Basketball sprite

Add the Basketball sprite from the sprite library.


4 - Create a custom 'go to top' block

We're going to create a custom block of our own that we'll use to move the basketball up to a random place at the top of the screen.

Create a custom block called 'go to top' and add the following code to the define  go to top block to make the basketball go to a random place at the top of the stage area.

define go to top go to x (pick random (-250) to (250)) y (250) when green flag clicked turn video [on v] // add it under here go to top

And then add the go to top block underneath the when clicked block.

Test that it works by clicking the green flag several times. The basketball should go to different random places at the top of the stage area.


5 - Make the ball fall

Now we will program the ball to fall down by changing it's y position. The y position sets where the sprite is on the Y axis (up and down). 

Add the following code underneath the go to top block.

define go to top go to x (pick random (-250) to (250)) y (250) when green flag clicked turn video [on v] go to top// add it under here forever change y by (-5) end


6 - Create a custom 'bounce ball' block

We're going to create a custom block that we'll use to bounce the basketball when we appear to touch it.

Create a custom block called 'bounce ball' and add the following code to the define  bounce ball block to make the basketball 'bounce' back up to the top of the stage area and then go to a new random place.

define go to top go to x (pick random (-250) to (250)) y (250) define bounce ball repeat until < (y position) > (180) > // repeat until it gets to the top change y by (10) // make it go up end go to top


7 - Detect when to bounce the basketball

We're going to use the video camera to put you into the game, every time you touch the ball it will make it bounce up! We can detect 'video motion' around the sprite by using the video [motion] on [sprite] block.

Add the following code inside the forever block and underneath the change y by -5 block:

define go to top go to x (pick random (-250) to (250)) y (250) define bounce ball repeat until < (y position) > (180) > change y by (10) end go to top when green flag clicked turn video [on v] go to top forever change y by (-5) // add the new code under here if < (video (motion v) on (sprite v)) > (25) > then bounce ball end end


8 - Game over

If the basketball falls all the way to the bottom of the screen then it's game over! So we need to add some code to detect if the ball goes all the way down.

Add the following inside the forever block and underneath the if then  block.

define go to top go to x (pick random (-250) to (250)) y (250) define bounce ball repeat until < (y position) > (180) > change y by (10) end go to top when green flag clicked turn video [on v] go to top forever change y by (-5) if < (video (motion v) on (sprite v)) > (25) > then bounce ball end if < (y position) < (-150) > then // add in this code stop [all v] end end


9 - Add more basketballs

To add more basketballs to your game and make it more difficult, we can duplicate the first basketball. This will create a copy of the sprite and it's code!

Right click on the basketball, click on the 'duplicate' option in the menu that appears.

That's all the steps to create your Keepy Up game, have fun playing it!


10 - Challenge!

Can you think of any ways you could make the game better? How about adding some sound effects or even keeping score!

3 - Add the Video Sensing extension

We're going to use the camera that's in your computer to take a video and put you in the game!

Add the Video Sensing Extension so that we can use the Video Sensing blocks.

Then add the following code to Basketball sprite, to turn on the camera on your computer.

when green flag clicked turn video [on v]

You may see a pop up asking you to allow Scratch to use your camera. Click on the Allow button otherwise Scratch will not be able to use your camera.


Join our club 😃

Create your profile, earn points & badges and learn how to code!

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more