Middle School Project

Welcome to another exciting project in the “Future Innovators: Cool STEM Projects to Change the World” series! In this project, you’re going to create a fun and interactive drone delivery game using Scratch. You’ll take control of a virtual drone, navigating through obstacles to deliver packages to different locations. This project introduces game development, basic logic, and movement concepts—all in a fun, easy-to-use environment.

By the end of this tutorial, you’ll have built a game where players pilot a drone and face challenges like navigating around buildings, trees, or even stormy weather. You’ll learn how to add package drop-offs and score points for successful deliveries. Best of all, you can customize the game with your own unique twists and obstacles!


What You Will Learn

  • How to use Scratch to create interactive games.
  • How to use logic blocks to control a virtual drone’s movements and actions.
  • How to design obstacles and goals using simple event-based programming.
  • How to implement a scoring system for deliveries.

STEM Learning Process

1. Science: Explore the physics of flying objects and how drones navigate through space.
2. Technology: Learn the basics of game development using Scratch’s visual programming tools.
3. Engineering: Design and build a game with moving parts, challenges, and goals.
4. Math: Use coordinate systems and logic to control the drone’s movements and interactions.


What You Need

  • A computer with internet access.
  • A Scratch account (free): Sign up at scratch.mit.edu.
  • A creative mindset for designing your own game world and obstacles.

How the Game Works

In this game, the player controls a drone to deliver packages to different locations on a map while avoiding obstacles. The drone must drop packages at specific targets and earn points for each successful delivery. Along the way, players will need to avoid obstacles like trees, buildings, and bad weather. The game can be made more challenging with timers, random events, and a scoring system.


Step-by-Step Guide to Building the Drone Delivery Game

Step 1: Sign Up for Scratch

If you don’t have a Scratch account yet, visit scratch.mit.edu, click Join Scratch, and create a free account. This will allow you to save your project and share it with others.

Step 2: Create a New Project

Once logged in, click Create in the top-left corner to start a new project.

Step 3: Choose Your Drone Sprite

  1. In Scratch, sprites are the characters and objects in your game. For the drone, you can either:
  • Choose a pre-made sprite from Scratch’s library (look for a helicopter or vehicle).
  • OR draw your own drone sprite using the costume editor to give it a unique design.
  1. Rename your sprite “Drone” so it’s easier to manage as you add more sprites later.

Step 4: Making the Drone Move

We’ll use the arrow keys to control the drone’s movement. First, we need to set up basic movement controls for the drone using the motion blocks in Scratch.

  1. Go to the Events section and drag the “When [green flag] clicked” block into the workspace.
  2. Go to the Control section and drag the “forever” block to create an infinite loop, which will keep the drone listening for key presses as long as the game is running.
  3. Inside the forever loop, use “if [key right arrow pressed]”, “if [key left arrow pressed]”, “if [key up arrow pressed]”, and “if [key down arrow pressed]” blocks to check for arrow key presses.
  4. Attach “change x by [10]” to move right and “change x by [-10]” to move left.
  5. Similarly, use “change y by [10]” to move up and “change y by [-10]” to move down.

Here’s how your drone’s basic movement code should look:

JavaScript
When [green flag] clicked
  forever
    if [key right arrow pressed] then
      change x by [10]
    if [key left arrow pressed] then
      change x by [-10]
    if [key up arrow pressed] then
      change y by [10]
    if [key down arrow pressed] then
      change y by [-10]

Step 5: Designing the Game World

Your game needs a background that represents the delivery area. This could be a city with streets, a rural area with trees, or any other setting you can imagine.

  1. Create a backdrop: Click on the Stage and go to the Backdrops tab to either:
  • Choose a pre-made backdrop from the Scratch library.
  • Draw your own city, town, or neighborhood using the drawing tools.
  1. Add Obstacles:
  • Add sprites like trees, buildings, or clouds from the Scratch library to act as obstacles.
  • Resize these sprites to make them smaller or larger, depending on how challenging you want the game to be.

Step 6: Adding Obstacles

We’ll add code to each obstacle sprite so that if the drone touches them, it loses points or has to restart the delivery.

  1. Select an obstacle sprite (like a tree or building).
  2. Go to the Events section and drag the “When [green flag] clicked” block.
  3. Add a forever block to constantly check if the drone touches the obstacle.
  4. Use an “if [touching [Drone]]” block (from the Sensing section) to check for collisions.
  5. If the drone touches the obstacle, you can:
  • Subtract points using the “change [score] by [-1]” block (from the Variables section).
  • Add an action like sending the drone back to the starting point with “go to [starting position]”.
JavaScript
When [green flag] clicked
  forever
    if [touching Drone] then
      change [score] by [-1]
      go to [starting point]

Step 7: Adding Delivery Targets

Now, let’s create delivery targets where the player must drop packages to score points. Each successful package drop will add to the player’s score.

  1. Create a new sprite to represent the delivery target (it could be a building, a house, or a landing pad).
  2. Add the following code to detect when the drone reaches the target:
  • Use an “if [touching [Drone]]” block to check when the drone reaches the target.
  • Add a “change [score] by [1]” block to increase the score.
  • Move the delivery target to a new location after each delivery using the “go to [random position]” block.
JavaScript
When [green flag] clicked
  forever
    if [touching Drone] then
      change [score] by [1]
      go to [random position]

Now your drone can deliver packages and earn points!


Step 8: Dropping the Packages

To add more interaction to the game, you can create a package drop feature, where players press the spacebar to drop a package.

  1. Add a package sprite: Create or choose a package sprite.
  2. Add code so that when the spacebar is pressed, the package drops from the drone’s location:
  • “When [space key] pressed”, “go to [Drone]”, and “change y by [-10]” will make the package fall.
  1. Use “if touching [delivery target]” to check if the package reaches the target.

Step 9: Adding a Scoring System

We’ve already added scoring for deliveries and penalties for hitting obstacles. Let’s make sure the player’s score is displayed on the screen.

  1. Go to the Variables section and create a new variable called “score”.
  2. Place the “set [score] to [0]” block at the beginning of your script (after the green flag is clicked).
  3. Every time the drone successfully delivers a package, use “change [score] by [1]” to increase the score.
  4. Display the score in the top-left corner of the screen to keep the player updated.

Step 10: Adding Difficulty with Time Limits (Optional)

To make the game more challenging, add a timer that limits how long the player has to make deliveries.

  1. Create a new variable called “timer”.
  2. Set the timer to 60 seconds when the game starts.
  3. Use the “change [timer] by [-1]” block every second to decrease the time.
  4. When the timer reaches 0, end the game by displaying a message like “Time’s up!”.

Step 11: Testing Your Drone Delivery Game

Once you’ve built your game, it’s time to test it out!

  1. Click the Green Flag to start the game.
  2. Use the arrow keys to control the drone and deliver packages.
  3. Drop packages on the delivery target using the spacebar.
  4. Avoid obstacles and score points for each successful delivery.

Challenge Your Friends!

Share your game with friends and see who can score the most points within the time limit!


Customizing Your Game

Here are some ways you can make your drone delivery game even cooler:

1. Add More Obstacles:

  • Create weather-based challenges like moving clouds that slow the drone down or lightning bolts that make the drone restart.

2. Create New Levels:

  • Once a certain score is reached, change the backdrop to represent a new level with harder obstacles.

3. Add Power-Ups:

  • Create items the drone can collect for extra points or speed boosts.

What’s Next?

Congratulations! You’ve built a drone delivery game where players can fly a virtual drone, avoid obstacles, and deliver packages. But don’t stop here—you can keep expanding the game by adding more features like faster speeds, new levels, and trickier obstacles.


Resources and Additional Help


Categorized in: