8. Break bricks¶
In this practice we are going to program a game that consists of breaking bricks with a ball that bounces off a bar. Each broken brick will give us a point.
We start the Scratch editor.
Press the language button in the top bar and choose English.
We delete the cat object by clicking on the trash can icon.
Added a new character, a control bar.
Press the button choose an object .
We look in the All section.
and select the Button2 object.
We carry out the following program for the control bar.
Press the green flag to test the operation of the program.
The bar should move horizontally at the bottom of the screen following the position of the mouse.
Added a new character, a brick.
Press the button choose an object .
We look in the All section.
and select the Button3 object.
Added a new character, a tennis ball.
Press the button choose an object .
We look in the Sports section.
and select the Tennis ball object.
We carry out the following programs for the tennis ball
Press the green flag to test the operation of the program.
Every time we press the space bar, a tennis ball should appear and move across the screen, bouncing off the walls and the control bar.
When the ball reaches the bottom of the screen, it disappears.
Now we will create the variable points that will store the points we got by breaking each brick.
We change the name of the variable to points
Finally, click on the OK button.
Next we will create the variable position that will store the position of each brick when placing the bricks on the screen.
We change the name of the variable to position
Finally we will create the program of the bricks.
Press the green flag to test the operation of the program.
When the program starts, all the bricks will appear at the top of the screen. Now we can play with the ball by pressing the space bar.
Challenges¶
Modify the program so that two rows of bricks appear at the top.
Duplicate the brick character, create another variable position2 and change it to the new brick.
Finally you have to lower the Y position of the new brick from 130 to 80.
Modify the program so that the game is over after three balls are lost from the bottom.
Modify the appearance of the characters to customize them to your liking.