Workshop › Lunar Lander › Step 1 of 31
Fire the engine and tilt the lander to touch down gently on the pad. Random terrain, gravity and thrust along an angle with sin and cos, rotating drawings, the rules of a safe landing, and debris when it goes wrong.
The moon's surface is a list of heights, one every 40 pixels. Random heights make hills. First we only make the list.
```js
const canvas = document.getElementById('game')
const ctx = canvas.getContext('2d')
const STEP = 40 // the ground is a line through a point every STEP pixels
let ground // y of the ground at x = 0, STEP, 2 * STEP, ...
function makeGround() {
const points = canvas.width / STEP + 1
ground = Array.from({ length: points }, () => 210 + Math.random() * 120)
}
makeGround()
```STEP is the distance between two ground points.Array.from({ length: points }, () => ...) makes a list of that length, filling each place with what the arrow
function returns: a random height from 210 to 330.Write the code under the three comment lines, then press Run.
Skills: Arrays and objects