10. Kill little martians

In this lab we are going to program a game that consists of killing, with a spaceship's laser, Martians that fall from the top of the screen.

_images/scratch3-p09-screen.png


  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. Now we choose a suitable backdrop for our game. We changed the stage backdrop for a sky with stars.

    Press the button choose a backdrop seleccionar-fondo.

    We look in the Space section.

    and select the Stars backdrop.

    _images/scratch3-fondo-stars.png


  5. Added a new character, a spaceship.

    Press the button choose an object seleccionar-objeto.

    We look in the All section.

    and select the Rocketship object.

    _images/scratch3-objeto-rocketship.png


  6. We added a new variable x that will store the position of the spaceship.

    Press the variables button boton-variables,

    click on create a variable boton-crear-variable.

    We change the name of the variable to x


  7. We make the program to start the ship at the bottom of the screen and make it move to the right and to the left.

    _images/scratch3-p09-rocket-01.png
  8. Press the green flag bandera-verde to test the operation of the program.


  9. Now we add a new object, a button that will make a laser beam blue.

    Press the button choose an object seleccionar-objeto.

    We look in the All section.

    and select the Button2 object.

    _images/scratch3-objeto-button2.png


  10. We program the button to behave like a laser beam. at the beginning we will turn the button up with small size.

    Each time the space key is pressed a new laser beam will appear.

    _images/scratch3-p09-button-01.png

    Each laser beam will travel up from the ship's current position to the top of the screen where it will disappear.

    _images/scratch3-p09-button-02.png
  11. Press the green flag bandera-verde to test the operation of the program.


  12. Added a new object, a Martian.

    Press the button choose an object seleccionar-objeto.

    We look in the Animals section.

    and select the Starfish object.

    _images/scratch3-objeto-starfish.png


  13. We carry out the necessary program so that clones of the Martians appear every so often in the upper part of the screen.

    _images/scratch3-p09-starfish-01.png


  14. We now complete the program for each clone. Each clone will appear in a random horizontal position. then the clone will move down bit by bit until it reaches the bottom or is hit by a laser beam. At that moment it disappears.

    _images/scratch3-p09-starfish-02.png


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



Challenges

  1. Add a condition for the ship to disappear when touched by a Martian and the game will be over.
  2. Change the parameters of the program to adjust its difficulty making more Martians appear per second and go down faster.
  3. Adds a double fire function for the spaceship when pressing the "up arrow" key.
  4. Invent another original modification for the program.