Coding Ireland STEM Report 2024 Have Your Say
Scratch Game
Expert
60 mins
145 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.

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.


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.


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


Join our club 😃

To view the remaining 5 steps and access hundreds of other coding projects please login or create an account.

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