Workshop › Breakout › Step 34 of 39
Play again
What we are doing
After winning or losing, the same click or Space starts a new game. A small line under the message tells the player.
```js
function launch() {
if (state === 'won' || state === 'lost') {
newGame()
return
}
ctx.font = '16px sans-serif'
ctx.fillText('Click to play again', canvas.width / 2, 280)
```
What it means
- At the top of
launch: if the game is over, start a new one and stop there (so it is not launched at once).
- The small line goes under the big message, back in the 16-pixel font.
Your turn
- At the top of
launch, above if (state !== 'serve') return, write the new if block.
- In
draw, inside the won/lost block, write the two lines under the big message.
Skills: Game states, Keyboard and mouse input
← One function for a new game A burst of particles →
All steps
- The field and the paddle
- Draw again and again
- Keep a number inside limits
- Follow the mouse
- A canvas shown at another size
- A ball with a velocity
- Draw a round ball
- Move the ball
- Bounce off the side walls
- Bounce off the ceiling
- The open floor
- Bounce off the paddle
- Aim with the paddle
- A row of bricks
- Draw the bricks
- A whole wall: a loop inside a loop
- A color for every row
- Circle meets box
- Break a brick
- Hitting the side of a brick
- Wait on the paddle
- Ride along with the paddle
- Launch the ball
- Click or press Space
- Remember which keys are held
- Steer with the arrow keys
- Three lives
- Lives and a hint on screen
- Game over
- Keep score
- Show the score
- Win the game
- One function for a new game
- Play again
- A burst of particles
- Break into sparks
- Move, fall and disappear
- Fade out
- Build it yourself: tough bricks