8. Break bricks

_images/scratch3-p07-screen.png

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.


  1. We start the Scratch editor.


  2. Press the language button boton-idioma in the top bar and choose English.


  3. We delete the cat object by clicking on the trash can icon.

    borrar-gato


  4. Added a new character, a control bar.

    Press the button choose an object seleccionar-objeto.

    We look in the All section.

    and select the Button2 object.

    _images/scratch3-objeto-button2.png


  5. We carry out the following program for the control bar.

    _images/scratch3-p07-button2-01.png


  6. Press the green flag bandera-verde to test the operation of the program.

    The bar should move horizontally at the bottom of the screen following the position of the mouse.


  7. Added a new character, a brick.

    Press the button choose an object seleccionar-objeto.

    We look in the All section.

    and select the Button3 object.

    _images/scratch3-objeto-button3.png


  8. Added a new character, a tennis ball.

    Press the button choose an object seleccionar-objeto.

    We look in the Sports section.

    and select the Tennis ball object.

    _images/scratch3-objeto-tennisball.png


  9. We carry out the following programs for the tennis ball

    _images/scratch3-p07-tennisball-01.png _images/scratch3-p07-tennisball-02.png


  10. Press the green flag bandera-verde 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.


  11. Now we will create the variable points that will store the points we got by breaking each brick.

    Press the variables button boton-variables,

    click on create a variable boton-crear-variable.

    We change the name of the variable to points

    _images/scratch3-crear-variable-puntos.en.png

    Finally, click on the OK button.


  12. Next we will create the variable position that will store the position of each brick when placing the bricks on the screen.

    Press the variables button boton-variables,

    click on create a variable boton-crear-variable.

    We change the name of the variable to position


  13. Finally we will create the program of the bricks.

    _images/scratch3-p07-button3-01.png _images/scratch3-p07-button3-02.png


  14. Press the green flag bandera-verde 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

  1. 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.


  2. Modify the program so that the game is over after three balls are lost from the bottom.


  3. Modify the appearance of the characters to customize them to your liking.