0% found this document useful (0 votes)
5K views6 pages

Breakout Tutorial For Scratch

This is a tutorial created for a coder dojo computer club to teach kids how to make a simple breakout game using Scratch, the computer programming software from MIT

Uploaded by

Niall Kane
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5K views6 pages

Breakout Tutorial For Scratch

This is a tutorial created for a coder dojo computer club to teach kids how to make a simple breakout game using Scratch, the computer programming software from MIT

Uploaded by

Niall Kane
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Making a breakout game using Scratch

Breakout is a game that requires you to bat a ball to hit blocks to make them disappear. This is a version of that game. First we are going to create the bricks. We are going to create the bricks by stamping the sprite in the positions we want. First we draw a brick in our paint editor. Set the costume editor to the lower left corner. This makes it a bit easier to set out the bricks

Duplicate the costume to create five different coloured brick costumes in the same sprite.

Make three variables, row, brickX and brickY. The row variable records the row that the brick is on. The brickX variable records the horizontal

Waterford Coder Dojo

position of the brick, and the brickY variable records the vertical position of the brick Put in the following script for the brick.

(((

))

The biggest potential pitfall in this script is if you have the maths in the wrong order in the set brickX part of the script. It is important that the script is in the correct order. It can be built up like this.

The purpose of this script is to calculate the starting position of each row. We have 9 bricks in the first row (row 0) and in each subsequent row there are 2 bricks less. We multiple by 50 to allow for the width of the brick and the space between the bricks and divide the number of bricks by 2 for half the screen and take the whole lot from 0 to move to the left of the centre. In the stage script put the following script to allow you to test what you've done.

Waterford Coder Dojo

Go ahead and click the green flag, you should have something like the following

If the brick you have drawn is bigger than 50 pixels wide or 30 pixels high all the bricks will blend in together. To fix this, shrink the brick using the shrink tool. Next we are going to draw the paddle. Go ahead and draw the paddle and put the following script

Now it is time to draw the ball. A small circle or an imported ball will do the trick. The script is the hardest part. The way this script works is every time the ball touches on of the coloured stamps, it draws a circle in the same colour as the background.

Waterford Coder Dojo

Our basic game should work now, but there are still a few problems. You only have one life, and there is no way to tell when all the bricks have been removed. We will try to solve these now. Giving yourself a number of lives can be done a number of ways, the easiest is to wrap the previous script from the repeat until key 'space' pressed until the end in a repeat loop with the number to give us the following script for the ball. (note we created a new variable for lives)

Waterford Coder Dojo

To detect if all the blocks are gone, we need to put in a detector bar. This detector bar will have to be repeated for each row. The detector bar takes the form of a narrow horizontal line the full width of the screen. The following script is used to detect if the blocks on the bottom row have been removed. The ghost effect makes the detector bar invisible when the game is in progress, but we hide it when they have finished their work, so they don't become visible at the end of the game. We use the variable row1Clear to record when the first row is clear. The detector can then be duplicated for the other rows changing only the y position of the detector, the colour of the row of bricks and the variable. This then gives the following scripts

Waterford Coder Dojo

We then need to initialise all the row clear variables by setting them to false. And we can create a if loop that when all the detectors are clear we declare that the player has won. We can do this by putting the following script on the stage and creating two backgrounds one a blank background and the next background with a script saying You Win.

The game now works and you can clear one level. Why don't you try to improve the game yourself. Some ideas you can try are adding scores adding more levels adding bonus items that drop from bricks when hit

Waterford Coder Dojo

You might also like