13. Landing rocket

In this practice we are going to program a game that consists of landing a rocket on the moon that will have a realistic movement with gravity and with the ignition of the engines. The objective is to start the engines at the correct time so that the rocket lands at low speed and does not crash.

_images/scratch3-p13-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 to the moon.

    Press the button choose a backdrop seleccionar-fondo.

    We look in the Space section.

    and select the Moon backdrop.

    _images/scratch3-fondo-moon.png


  5. Next we add a new character, a rocket.

    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. Now we will create the variable velocity that will store the rate of fall of the rocket on the moon. If this variable is too high when the rocket hits the moon, the rocket will be destroyed.

    Press the variables button boton-variables,

    click on create a variable boton-crear-variable.

    We change the name of the variable to speed

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

    Finally, click on the OK button.


  7. Now we will create the variable fuel that will store the amount of fuel that the rocket has to be able to start the engines and slow down the fall on the moon. If the fuel runs out, the rocket will not be able to break the fall.

    Press the variables button boton-variables,

    click on create a variable boton-crear-variable.

    We change the name of the variable to fuel

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

    Finally, click on the OK button.


  8. We make a subroutine that initializes the position and size of the rocket at the start of the program. It will also set the initial values ​​of the variables.

    _images/scratch3-p13-inicio.png


  9. We make a subroutine that moves the rocket during the flight. The speed will increase up when we start the motors and will increase down with the motors off.

    _images/scratch3-p13-vuelo.png


  10. We carry out a subroutine that stops the rocket when it reaches the ground and determines if the speed is too high or if it is correct for a good landing.

    _images/scratch3-p13-aterrizaje.png


  11. We program the main program that gathers all the subroutines.

    _images/scratch3-p13-programa.png


  12. Next we add a new character, a button that will serve as a landing platform.

    Press the button choose an object seleccionar-objeto.

    We look in the All section.

    and select the Button2 object.

    _images/scratch3-objeto-button2.png


  13. We add the Button initialization program.

    _images/scratch3-p13-button2-init.png


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


Challenges

  1. Add meteorites that move from side to side slowly so that the rocket has to avoid them.
  2. Play several times to establish the best mark of fuel left over after the rocket has landed. From there you can lower the starting fuel in the program to make the game more difficult.