In this game, players control a truck to collect bananas (or recyclable items) falling from the sky.
The player earns points by collecting items, while missing items or hitting obstacles may result
in penalties. This fun game also teaches kids the importance of recycling!
when green flag clicked
go to x: (start x position) y: (start y position)
forever
if <key [up arrow] pressed?> then
change y by (5)
end
if <key [down arrow] pressed?> then
change y by (-5)
end
end
Step-by-Step Guide: How to Make a Recycling Truck
Game in Scratch
Introduction
In this game, players control a truck to collect bananas (or recyclable items) falling from the sky.
The player earns points by collecting items, while missing items or hitting obstacles may result
in penalties. This fun game also teaches kids the importance of recycling!
Step 1: Plan Your Game
Before starting, outline the main components:
1. Objective: Control the truck to collect bananas (or items) and earn points within a time
limit.
2. Key Features:
○ Moving truck controlled by arrow keys.
○ Falling bananas or items.
○ Score counter.
○ A timer for gameplay duration.
○ End screen with a final score and motivational recycling message.
3. Sprites and Backdrops:
○ Sprites: Truck, bananas, bonus items, hazards.
○ Backdrop: A road or cityscape.
Step 2: Set Up the Game
1. Create the Stage and Backdrops
● Go to the Backdrops tab.
● Create a background for the game, such as a road or recycling area.
● Add a Game Over backdrop to display the final score and message.
2. Add Sprites
● Truck:
○ Upload or draw a truck sprite.
○ Adjust its size to fit the road.
● Bananas/Items:
○ Add a banana sprite for the collectible items.
○ Duplicate it for bonus items (like golden bananas) or hazards (like trash).
● Start Button:
○ Create a "Start Game" button to initiate gameplay.
Step 3: Code the Truck
Movement
Make the truck move up and down with arrow keys:
when green flag clicked
go to x: (start x position) y: (start y position)
forever
if <key [up arrow] pressed?> then
change y by (5)
end
if <key [down arrow] pressed?> then
change y by (-5)
end
end
Step 4: Code the Falling Bananas
1. Create Bananas as Clones
● Add code for bananas to fall from random positions and be deleted when collected or
missed:
when green flag clicked
hide
forever
wait (pick random 1 to 2) seconds
create clone of [myself v]
end
when I start as a clone
show
go to x: (pick random -240 to 240) y: (180)
repeat until <y position < -180>
change y by (-5) // Falling speed
wait (0.05) seconds
end
delete this clone
2. Collect Bananas
● Detect when the truck touches a banana:
scratch
CopyEdit
when I start as a clone
forever
if <touching [Truck v]?> then
change [score v] by (1)
play sound [Collect v]
delete this clone
end
end
Step 5: Add Scoring and Timer
Score Counter
● Create a variable called score and update it when bananas are collected:
scratch
CopyEdit
when green flag clicked
set [score v] to (0)
Timer
● Add a timer to limit gameplay:
scratch
CopyEdit
when green flag clicked
set [time v] to (60) // Time limit
repeat until <(time) = (0)>
wait (1) second
change [time v] by (-1)
end
broadcast [ENDGAME]
Step 6: Add Endgame Logic
When the timer runs out, show the final score and switch to the Game Over screen:
scratch
CopyEdit
when I receive [ENDGAME]
switch backdrop to [Game Over]
say [Your score: (score)] for (3) seconds
stop [all v]
Step 7: Add Bonus Items and Hazards
● Bonus Items:
○ Add golden bananas worth extra points.
scratch
CopyEdit
if <touching [Truck v]?> then
change [score v] by (5) // Bonus points
play sound [Bonus v]
delete this clone
end
● Hazards:
○ Add items like trash that subtract points or end the game:
scratch
CopyEdit
if <touching [Truck v]?> then
change [score v] by (-1)
play sound [Penalty v]
delete this clone
end
Step 8: Add Sounds and Effects
● Add background music:
scratch
CopyEdit
when green flag clicked
play sound [BackgroundMusic v] until done
● Add effects for bananas and the truck:
scratch
CopyEdit
change [ghost v] effect by (10) // Fading effect
Step 9: Create a Start Screen
● Add a "Start Game" button:
scratch
CopyEdit
when this sprite clicked
broadcast [STARTGAME]
● Add code to hide the button and start the game:
scratch
CopyEdit
when I receive [STARTGAME]
hide
broadcast [STARTGAME]
Step 10: Publish and Share
1. Test the game thoroughly to ensure all features work smoothly.
2. Add instructions for players:
○ Use the Notes and Credits section to explain controls and the objective.
3. Publish the game on Scratch by clicking Share.
4. Add a catchy title and thumbnail for your project.
Optional Features to Enhance the Game
1. Levels:
○ Increase difficulty by spawning bananas faster or adding more hazards.
2. Achievements:
○ Display milestones like "10 Bananas Collected!".
3. Educational Messages:
○ Flash recycling tips or fun facts between levels.
Conclusion
This step-by-step guide takes you through planning, building, and refining a fun and educational
game in Scratch. By following these steps, you’ll have a polished recycling-themed truck game
that’s perfect for sharing with friends, family, or the Scratch community.