Workshop › OutRun-style Racer › Step 42 of 44
Finished!
What we are doing
When the race is over, big text in the middle says so, and tells the player how to race again.
```js
if (state === 'finished') {
ctx.textAlign = 'center'
ctx.font = 'bold 28px sans-serif'
ctx.fillText('Finished!', W / 2, H / 2 - 30)
ctx.font = 'bold 16px sans-serif'
ctx.fillText('Press Space to race again', W / 2, H / 2 - 6)
}
```
What it means
- Only when finished:
textAlign = 'center' centers the text on W / 2; a bigger font for the title, the normal one
for the line under it.
Your turn
In draw, under the Lap line, write the if block.
Skills: Drawing on a canvas
← The finish line Race again →
All steps
- Sky and ground
- Draw again and again
- Perspective
- One piece of road
- A road made of segments
- Where we are on the track
- The road ahead
- Stripes
- Paint from far to near
- Kerbs and a center line
- Striped grass
- Moving is one number
- Which keys are down?
- The gas pedal
- Brake, coast and a top speed
- Your car
- Speedometer
- A pedal for phones
- Move the camera sideways
- Steering
- No turning on the spot
- The grass is slow
- Steering by touch
- A track with curves
- Bend the road
- No jumps in the curve
- Which segment am I on?
- Curves pull you outwards
- Other cars
- Distance on a loop
- Cars that shrink with distance
- Traffic moves
- Rear-end crash
- Counting laps
- Show the lap
- A lap timer
- Show the time
- Best lap
- Show the best lap
- Racing or finished
- The finish line
- Finished!
- Race again
- Build it yourself: beat the clock