Lunar Lander FUEL OPTION
In this version of the game, you will need to land the Lunar Lander before you run out of fuel.

Create our Fuel Tank
Add this code to the end of the CREATE function of the Level1State.
This code will create our fuel tank with 1000 units of fuel. We will also add text to the screen so we can monitor the fuel level.
// create fuel tank (create a variable called fueltank to hold the amount of fuel left)
this.FuelTank = 1000;
// add text to the screen to show how much fuel is left
this.FuelStatus = game.add.text(0,0,'Fuel: ' + this.FuelTank, {font: '15px Arial', fill: '#02f20e' });
Run Your Code and check for errors.
You should see the Fuel Status indicator on the top left of your game screen.
Press F12 to open the Developer Tools, click Console tab and make sure there are no errors.
Burn Fuel
Add this code to replace the end of the UPDATE function of the Level1State.
This code will decrease the amount of Fuel in our Fuel Tank each time we run the engines.
// if rocket engines are on, use 10 units of fuel
if (RocketEngineOff === false) {
this.FuelTank = this.FuelTank - 10;
this.FuelStatus.text = 'Fuel: ' + this.FuelTank;
}
Run Your Code and check for errors.
Play the game, as you move the rocket, the fuel status should decrease.
Check if no more Fuel
If there is no more fuel, we need to prevent the engines from being turned on.
Change each of the IF statements, which run the engines, to include a check for fuel.
// check if down engines are on
if (this.keyboard.isDown(Phaser.Keyboard.UP) && this.FuelTank > 0) {
// check if left engine is on
if (this.keyboard.isDown(Phaser.Keyboard.LEFT) && this.FuelTank > 0) {
// check if right engine is on
if (this.keyboard.isDown(Phaser.Keyboard.RIGHT) && this.FuelTank > 0) {
Run Your Code and check for errors.
If the rocket runs out of fuel, the engines stop working and the Lunar Lander crashes.
You're done! You are a coder!!
What other things can you add to this game?
What other games can you make up using this code!?