Workshop › Pac-Man-style Maze Chase › Step 34 of 42
Play again
What we are doing
Space starts a new game when the game is over; on a phone, any touch does. reset sets score, lives, level and
pellets back and places everyone.
```js
if (event.key === ' ' && state === 'over') reset()
if (state === 'over') {
reset()
return
}
```
What it means
- The key listener restarts only on Space and only after the game is over.
- In
pointerup, a finished game restarts on any touch, before the swipe is even measured.
Your turn
- In the key listener, above its last
}), write the Space line.
- In the
pointerup listener, under swipeStart = null, write the restart block.
Skills: Keyboard and mouse input
← Game over Frighten the ghosts →
All steps
- The maze as text
- The game loop
- Draw the walls
- A set of pellets
- Draw the pellets
- The player
- Where can you walk?
- What a mover remembers
- One frame of movement
- Move every frame
- Turns you can press early
- Glide between tiles
- Turn back at once
- Swipes on a phone
- Eat the pellets
- Show the score
- Clear the maze
- A red ghost
- A ghost never turns back
- The ghost walks
- The ghost hunts you
- Four ghosts in the house
- One by one out of the house
- Scatter or chase?
- Every ghost to its corner
- Pink cuts you off
- Orange is shy
- Cyan works with red
- Wait for the first key
- Tell the player to start
- Three lives
- Caught!
- Game over
- Play again
- Frighten the ghosts
- Power pellets work
- Scared ghosts wander slowly
- Eat a scared ghost
- Blue, then flashing
- Harder levels
- A best score that lasts
- Build it yourself: the slow tunnel