Workshop › Lunar Lander › Step 20 of 31
After a landing or a crash, Space (or a tap) starts a new flight over new hills. The decision lives in one function,
next().
```js
if (event.key === ' ') next()
function next() {
if (state !== 'flying') reset()
}
canvas.addEventListener('pointerdown', (event) => {
if (state !== 'flying') {
next()
return
}
```next(); next starts a new flight only when not flying.next() too, and return stops it from also holding a steering key.keydown listener, add if (event.key === ' ') next() as its last line.// Touch: ... comment, write next, followed by an empty line.pointerdown listener, write the if (state !== 'flying') block.Skills: Keyboard and mouse input, Game states
← Landing or crashing Landed or crashed? →