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.
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.
Now we choose a suitable backdrop for our game. We changed the stage backdrop to the moon.
Press the button choose a backdrop .
We look in the Space section.
and select the Moon backdrop.
Next we add a new character, a rocket.
Press the button choose an object .
We look in the All section.
and select the Rocketship object.
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.
We change the name of the variable to speed
Finally, click on the OK button.
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.
We change the name of the variable to fuel
Finally, click on the OK button.
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.
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.
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.
We program the main program that gathers all the subroutines.
Next we add a new character, a button that will serve as a landing platform.
Press the button choose an object .
We look in the All section.
and select the Button2 object.
We add the Button initialization program.
Press the green flag to test the operation of the program.
Challenges¶
- Add meteorites that move from side to side slowly so that the rocket has to avoid them.
- 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.