How to create a brick breaker game on scratch

A classic! Creating a Brick Breaker game on Scratch is a fun and educational project. Here's a step-by-step guide to help you get started:

Game Overview

In Brick Breaker, the player controls a paddle at the bottom of the screen, and the goal is to break bricks by bouncing a ball off the paddle. The game ends when all the bricks are broken or the ball hits the bottom of the screen.

Scratch Setup

  1. Create a new project in Scratch by clicking on "File" > "New Project" or by using the shortcut key "Ctrl + N" (Windows) or "Cmd + N" (Mac).
  2. Set the stage size to 480x360 pixels by clicking on "File" > "Project Settings" > "Stage" and adjusting the values.
  3. Create a new sprite by clicking on "Sprites" > "New Sprite" or by using the shortcut key "Ctrl + Shift + S" (Windows) or "Cmd + Shift + S" (Mac). Name the sprite "Paddle".

Paddle Sprite

  1. Add a rectangle shape to the Paddle sprite by clicking on "Costumes" > "New Costume" and then selecting "Rectangle" from the shape options.
  2. Set the rectangle's size to 100x20 pixels by adjusting the values in the "Costume" panel.
  3. Add a script to the Paddle sprite by clicking on the "Scripts" tab and then clicking on the "New Script" button. This script will control the paddle's movement.

Paddle Movement Script

  1. Add the following code to the Paddle script:
    when green flag clicked
    forever
     if key [left arrow] pressed
       set x to (x - 5)
     if key [right arrow] pressed
       set x to (x + 5)

    This script will move the paddle left and right when the left and right arrow keys are pressed.

Ball Sprite

  1. Create a new sprite by clicking on "Sprites" > "New Sprite" or by using the shortcut key "Ctrl + Shift + S" (Windows) or "Cmd + Shift + S" (Mac). Name the sprite "Ball".
  2. Add a circle shape to the Ball sprite by clicking on "Costumes" > "New Costume" and then selecting "Circle" from the shape options.
  3. Set the circle's size to 10x10 pixels by adjusting the values in the "Costume" panel.
  4. Add a script to the Ball sprite by clicking on the "Scripts" tab and then clicking on the "New Script" button. This script will control the ball's movement.

Ball Movement Script

  1. Add the following code to the Ball script:
    when green flag clicked
    forever
     move 2 steps
     if touching Paddle
       bounce off Paddle
     if touching edge
       bounce off edge

    This script will move the ball 2 steps at a time and bounce it off the paddle and edges of the stage.

Brick Sprite

  1. Create a new sprite by clicking on "Sprites" > "New Sprite" or by using the shortcut key "Ctrl + Shift + S" (Windows) or "Cmd + Shift + S" (Mac). Name the sprite "Brick".
  2. Add a rectangle shape to the Brick sprite by clicking on "Costumes" > "New Costume" and then selecting "Rectangle" from the shape options.
  3. Set the rectangle's size to 50x20 pixels by adjusting the values in the "Costume" panel.
  4. Add a script to the Brick sprite by clicking on the "Scripts" tab and then clicking on the "New Script" button. This script will control the brick's behavior.

Brick Behavior Script

  1. Add the following code to the Brick script:
    when green flag clicked
    forever
     if touching Ball
       delete this clone

    This script will delete the brick when the ball touches it.

Game Logic

  1. Add a script to the Stage sprite by clicking on the "Scripts" tab and then clicking on the "New Script" button. This script will control the game logic.
  2. Add the following code to the Stage script:
    when green flag clicked
    forever
     if all bricks broken
       stop [all]
     if ball hits bottom
       stop [all]

    This script will stop the game when all the bricks are broken or the ball hits the bottom of the stage.

Putting it all together

  1. Add the Paddle, Ball, and Brick sprites to the stage by dragging and dropping them from the "Sprites" panel.
  2. Set the initial position of the Paddle, Ball, and Brick sprites by adjusting their x and y coordinates in the "Properties" panel.
  3. Run the game by clicking on the "Green Flag" button or by using the shortcut key "Ctrl + Enter" (Windows) or "Cmd + Enter" (Mac).

That's it! You now have a basic Brick Breaker game running on Scratch. You can customize the game by adding more features, such as scoring, power-ups, and levels. Have fun and happy coding!