Workshop › Lunar Lander › Step 15 of 31

The engine

What we are doing

The engine is under the lander and always pushes the way the lander points. Upright it pushes straight up; tilted, part of the push goes sideways. sin and cos split the push into its two parts.

```js
const THRUST = 0.1 // speed gained per frame of engine, along the direction the lander points

function burning() {
  return state === 'flying' && keys.ArrowUp
}

  if (burning()) {
    // The engine pushes along the direction the lander points: angle 0 is straight up.
    lander.vx += Math.sin(lander.angle) * THRUST
    lander.vy -= Math.cos(lander.angle) * THRUST
  }
```

What it means

Your turn

  1. Above const SPIN write the THRUST constant.
  2. Above function touchdown() {, write burning, followed by an empty line.
  3. In update, under the two arrow lines, write the if (burning()) block.

Skills: Velocity and gravity

All steps

  1. Random hills
  2. Draw the hills
  3. A landing pad
  4. The height at any x
  5. The lander
  6. Draw it around its own middle
  7. Two feet
  8. The game loop
  9. Moon gravity
  10. Around the sides
  11. Flying or not
  12. Touching the ground
  13. Remember held keys
  14. Tilt
  15. The engine
  16. A flickering flame
  17. Fuel
  18. Touch controls
  19. Landing or crashing
  20. Fly again
  21. Landed or crashed?
  22. Readouts
  23. Levels
  24. Score
  25. Next level or new game
  26. A narrower pad
  27. A high score
  28. Burst into pieces
  29. Pieces fall and fade
  30. Draw the wreck
  31. Build it yourself: wind