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.
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
Add the Basketball sprite from the sprite library.
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
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]
Scratch Extensions are additional sets of blocks that expand the capabilities of your Scratch projects. They allow you to:
When you add an extension to your project:
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.
You can create your own custom blocks and give them their own instructions (code). To create a custom block follow these steps:
A 'Define My Block Name' will appear in the code area. You can add your code underneath this and then use the My Block Name block in the 'My Blocks' toolbox anytime you wish to run that code.
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