logo
  • Home
  • Student Creations
  • Start Your Chapter
  • Create A Game
  • Contact
  • About
Create Your Own Game

Start coding your own game from scratch!

Try This Project

Apple Catching

In this Scratch project, you'll build a game
where you will control a bowl to catch as
many apples/other objects as it can. Use
your arrow keys to not drop any apples!

You'll Learn:

  • Moving sprites with arrow keys

    Using loops and conditions

    Keeping score

You'll Learn:

  • A Scratch account (free!)

    Internet access

    Your imagination ✨

Step-by-Step Code

First, create 3 objects →

  • an object of your choice that will be falling
  • a broken version of that object
  • an object that will catch those objects

Within the first 2 objects, go to costumes and add both the broken versions and
unbroken, so within each of the first 2 objects you should have 2 costumes

1. Bowl Movement

This part of the code controls the movement of the bowl:

  • when [green flag] clicked: Starts the script when the green flag is clicked.
  • forever: Repeats the following actions continuously.
  • if <key [right arrow] pressed?> then: Checks if the right arrow key is pressed. If this is true:
    • change x by (10): Moves the bowl 10 steps to the right.
  • if <key [left arrow] pressed?> then: Checks if the left arrow key is pressed. If this is true:
    • change x by (-10): Moves the bowl 10 steps to the left.

This allows the player to move the bowl left and right to catch the apples.

2. Game Over Timer

This script waits for a set time before ending the game.

  • when [green flag] clicked: Starts the script when the game begins.
  • wait (100) seconds: Waits 100 seconds before proceeding.
  • say [game over!] for (0.3) seconds: Displays "game over!" on the screen for 0.3 seconds.
  • stop [all]: Ends all scripts in the game

This creates a timer that ends the game after 100 seconds.

3. Apple Spawning and Scoring

This script controls the apples and the scoring.

  • when [green flag] clicked: Starts the script when the game begins.
  • set [score] to (0): Resets the score to 0 at the beginning.
  • forever: Repeats the following actions continuously.
    • if <touching [Bowl]> then: Checks if the apple touches the bowl. If this is true:
      • change [score] by (1): Increases the score by 1.
      • go to [random position]:Moves a new apple to a new random position at the top.
      • set y to (180): Resets the apple's starting y-coordinate to the top of the screen.

This creates a timer that ends the game after 100 seconds.

4. Apple Falling and Breaking:

This script handles the falling apples and game-over condition.

  • when [green flag] clicked: Starts the script when the game begins.
  • go to x: [random position] y: (180): Place the apple at the top of the screen in a random horizontal position.
  • forever: Repeats the following actions continuously.
    • change y by (-5):Moves the apple downward by 5 steps every loop.
    • if <y position <(-170)> then: Checks if the apple's y-coordinate is below -170 (off the bottom of the screen). If it is true:
      • go to x: [random position] y: (180):
        Moves the apple back to the top at a random position.
      • set y to (180):
        Resets the y-coordinate to the top.
  • if <touching color [brown]> then:Checks if the apple touches the ground (brown color). If this is true:
    • switch costume to [costume1]: Changes the apple's appearance (e.g., to a broken apple).
    • stop [all]: Ends the game.

This creates a timer that ends the game after 100 seconds.

How It All Works Together

  • The bowl moves left and right, allowing the player to catch falling apples.
  • Apples fall from the top and reset to a random position when caught.
  • Points are awarded for catching apples, and the game ends either when time runs out (100 seconds) or when an apple touches the ground.
  1. Test and Debug Tips:
    • You may confuse the backdrop and object, so ensure that you check your code frequently to ensure proper development in the game.
    • Be specific about the loops, in scratch there are many types (e.g., if else, if, forever, etc)
    • Make sure you add a new costume within the same object and not make a whole new object, again check your code frequently!!
Next Steps

Reflect on what worked well in this coding experience and what could be improved.

  • Home
  • Student Creations
  • Start Your Chapter
  • Create A Game
  • Contact
  • About
  • Instagram