Introduction
We’re going to make a recycling game! Catch the falling items, and put them in the correct recycling bins.
Use the arrow keys to run left and right
Press space bar to throw what you’re carrying
Get the rubbish in the correct recycling bin
Step 1: Create the character that will pick up the rubbish
Activity Checklist
- Start a new Scratch project.
- Change the name of Sprite1 to cat by clicking on the blue
i
symbol - Make sure that it will only flip left-right with the side-to-side arrow.
- Create a variable, for this sprite only, called runningspeed
- Create a variable, for this sprite only, called maxspeed
- Create a variable, for this sprite only, called cats-direction
- Untick all three variables so they’re not shown on the Stage
- Use the Make a Block button in More Blocks to create a new custom block
- Name the new custom block reset
Add a script to the reset block that will put the cat in the right starting place and set the speed variables
- Create another custom block, called run
Add the following script to run, to make it possible for the cat to run at the runningspeed, and slow down gradually
Combine these when the green flag is clicked
Create a custom block called “change direction if needed”. It should take one number input called direction
Create a custom block called speed up if possible which will increase speed, but only until the cat reaches maxspeed
Start to bring these together with a new custom block called handle button press which takes one number input called button-direction
Finally, add a script block that will use these custom blocks to control the cat’s running
Duplicate each of the cat’s two costumes. We want two of the first costume, and two of the second costume. This will prevent the running animation from flickering too much
Save your project
Test Your Project
Click the green flag.
- Use the left and right arrows to run from side to side
- If you let go of the arrow key after picking up speed, the cat should slow down gradually instead of stopping instantly
- If you switch directions while running, the cat should skid in the wrong direction briefly before switching
Things to try
- Try adjusting the speeds - the number in speed up if possible controls how fast the cat accelerates, the maxspeed value in reset controls the cat’s top speed.
Step 2: Add falling rubbish
It’s time to make items for the cat to recycle!
Activity Checklist
Prepare the sprite
- Upload a new sprite, choosing Resources/can.png
- Switch to the Costumes tab, and upload another costume using Resources/jar.png
- Upload another costume using Resources/newspaper.png
- The sprite should now have three costumes: a can, a jar and a newspaper
- Click on the blue
i
next to the sprite, and rename the sprite to be called object - Resize the sprite by clicking on the Shrink button at the top
- Click on the Sprite in the main stage window several times, until it is smaller than the cat
Get the rubbish to fall from the sky
- Create a variable that will control the speed the rubbish falls, called speed
- Untick the variable so the value isn’t shown on the main stage
Create a custom block called reset that will set the speed to 0 at the start
Create a custom block called falling that will make the object fall at this speed
Create a custom block called gravity that will make it speed up as it falls, but stop when it hits the ground
Create a custom block called choose object type that will choose a type of rubbish
Create a custom block called start at the top that makes each new bit of rubbish start at a different place
Create a custom block called new object every four seconds
Bring it all together by creating the following script
Test Your Project
Click the green flag. The cat should still be able to run around, but now rubbish should rain from the sky, spinning as it falls.
Save your project
Things to try
- Try changing new object every four seconds to make rubbish fall more or less often
- Try changing gravity to change the speed that objects fall
Step 3: Carrying the rubbish
Now we want to make the cat to be able to pick up fallen rubbish and carry it.
Activity Checklist
Select the rubbish object sprite.
Create variables that will let us describe the different costumes of object
- Create a new variable, for this sprite only, called can
- Create a new variable, for this sprite only, called jar
- Create a new variable, for this sprite only, called newspaper
- Untick them all so they’re not shown on the stage
Modify the existing reset custom block so that it looks like this. The numbers should match the costume numbers for the sprite.
Create variables to control what the cat is carrying
- Create a new variable, for this sprite only, called nothing
- Create a new variable, for all sprites, called carrying
- Untick them both so they’re not shown on the stage
Modify the existing reset custom block, to include setting both nothing and carrying to 4. It should end up looking like this.
Control how objects can be carried
Create a new custom block called wait to be carried that lets the cat pick up an object if it’s not already carrying something. This will include creating a new event to broadcast carry-change
Create a new script so each new piece of rubbish can be carried
Test Your Project
Try out your game again.
The cat can carry an item of rubbish, and will drop it when you press the space bar.
Save your project
Step 4: Throwing the rubbish
The next step is for the cat to be able to throw the rubbish it’s carrying into the air instead of dropping it.
Activity Checklist
Create a custom block called throw in the air
Modify the existing wait to be carried block so that the cat throws the object instead of dropping it when you press space. It should end up like this.
Test Your Project
Try out your game again.
The cat can carry an item of rubbish, and will throw it in the air when you press the space bar. It will fall back to the ground and can be picked up again.
Save your project
Step 5: Creating recycling bins
Activity Checklist
Start by setting up a background for the bins.
- Click on Stage
- Click on the Backdrops tab
- Click on Choose backdrop from library and choose a background like boardwalk
- Delete the original blank backdrop ‘backdrop1’
Add bins to the background
- Click on Convert to vector
- Click on Import on the Backdrops tab
- Choose Resources/bin.png
- Click on Select
- Select the bin and move and resize it to put it on the boardwalk path
- Add two more bins so it ends up looking something like this:
Add labels to the bins
- Click on Text
- Add labels to the bins - one for metal, one for glass, one for paper
Add the bin openings
- Click on Paint new sprite
- Click on the Costumes tab
- Click on Convert to vector
- Draw a filled oval that matches the opening for one of the bins
- Click on the blue
i
and rename the Sprite to bin-can Add a script that draws the bin behind thrown rubbish
- Duplicate the sprite
- Call the duplicate bin-jar
- Move it to cover the second bin opening
- Duplicate the sprite again
- Call the duplicate bin-newspaper
Move it to cover the third bin opening
Get the rubbish to go in the bins
- Click on the object sprite
Create a new custom block called rubbish binned
Create a new custom block called go in the bin
Modify the existing wait to be carried custom block so that thrown objects can go in the bin instead of falling back down. It should end up looking like this.
Test Your Project
Try out your game again.
The cat can now throw items into bins. Items will only go into the correct bins, otherwise they’ll fall back down onto the ground.
Save your project
Step 6: Keep score
- Create a new variable, for all sprites, called score
- Move the score variable in the stage up into the corner
Modify the custom reset block in the scripts for the rubbish objects to reset the score to 0, so it should look like:
Modify the custom rubbish binned block so that it adds to the score. It should look like:
Test Your Project
Try out your game again.
The cat gets a point for every item that is put into the correct recycling bin.
Save your project
Well done, you’ve finished! Now you can enjoy your game!
Don’t forget you can share your game with all your friends and family by clicking on Share on the menu bar!