Keepy Ups

Scratch GameHard

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.

1

Create a new Scratch project

Create a new Scratch project and delete the cat sprite.

https://scratch.mit.edu

2

Add a basketball

Open the sprite library and scroll down and find the basketball sprite. Select the sprite by clicking on it and then click 'OK' to add it to your project.


3

When green flag clicked

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

Add the following code to the basketball sprite:

  1. events when clicked 
  2. sensing turn video [on] 

4

Create a '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.

Go to the 'More Blocks' toolbox and click the 'Make a Block' button. This will open up a box where you can enter the name of your new block, call it 'go to top' and click the 'OK' button.

This will create a go to top block in the 'More Blocks' toolbox and adefine go to top block in our code area. The code blocks we put under the  define go to top block will be the instructions to move the basketball up to the top of the screen.


5

Program what 'go to top' does

Now we will program what the define go to top does. Add the following code underneath the define go to top block:

  1. motion go to x: 0 y: 0 
    (replace x: [0] with
    operators pick random -250 to 250)
    (replace y: [0] with [250])

Next, add the following block underneath the turn video [on] block:

  1. moreblocks go to top 

6

Make the ball fall

Now we will program the ball to fall down by changing it's y position. Add the following code underneath the go to top block:

  1. control forever 
    1. motion change y by -5 

7

Create a 'bounce ball' block

We're going to create a custom block of our own that we'll use to bounce the basketball.

Go to the 'More Blocks' toolbox and click the 'Make a Block' button. This will open up a box where you can enter the name of your new block, call it 'bounce ball' and click the 'OK' button.

This will create a bounce ball block in the 'More Blocks' toolbox and a define bounce ball block in our code area. The code blocks we put under the define bounce ball block will be the instructions to bounce the basketball.


8

Program what 'bounce ball' does

The instructions for define bounce ball will make the ball go up until it reaches the top of the screen, then we will use the go to top block to put the ball in a random place and start falling again.

Add the following code underneath the define bounce ball block:

  1. control repeat until  
    (drag a operators   >   block into the condition)
    (replace the first [] with motion y position)
    (replace the second [] with [190])
    1. motion change y by 10 
  2. moreblocks go to top 

9

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] of [this sprite] block.

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

  1. control if then 
    (drag a operators   >   into the condition)
    (replace the first [] with sensing video [motion] of [this sprite])
    (replace the second [] with [25])
    1. moreblocks bounce ball 

10

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 you added in the last step:

  1. control if then 
    (drag a operators   <   into the condition)
    (replace the first [] with motion y position)
    (replace the second [] with [-150])
    1. control stop [all] 

11

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.


12

Play and improve the game!

That's all the steps to create your Keepy Up game!

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

End of lesson
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