Workshop › Pinball › Step 20 of 42
Points for every hit
What we are doing
Each bumper hit gives 100 points, and the score is written at the top left of the table.
```js
score += 100
ctx.fillStyle = 'white'
ctx.font = 'bold 16px sans-serif'
ctx.textAlign = 'left'
ctx.fillText('Score ' + score, 30, 50)
```
What it means
score += 100 at the end of hitBumper adds the points.
font sets the size and style of text; textAlign = 'left' makes it start at the given x.
fillText(text, x, y) writes the text; 'Score ' + score joins the word and the number.
Your turn
- In
hitBumper, at the end, write score += 100.
- In
draw, at the end (under the ball), leave an empty line and write the four text lines.
Skills: Game states, Drawing on a canvas
← A score and a fresh start Remember which bumper was hit →
All steps
- Paint the table
- Draw one wall
- A list of walls
- The game loop
- A ball in the lane
- Draw the ball
- Move by the velocity
- Launch with Space
- Gravity
- Does the ball touch a wall?
- Push the ball out
- Bounce off the wall
- Small steps and a speed limit
- Ready or playing
- The next ball
- Three bumpers
- The ball meets a bumper
- A bumper kicks
- A score and a fresh start
- Points for every hit
- Remember which bumper was hit
- Light it up
- Lit for a moment, points once
- Two flippers
- Where is the tip?
- Flippers stop the ball
- Which keys are held?
- Which way to turn
- Flip!
- A moving wall
- The flipper throws
- Three balls
- Balls left and game over
- Play again
- Remember the best score
- Launch on letting go
- Pull the spring
- Show the spring
- Two thumbs
- Pull with a finger
- Tap to play again
- Build it yourself: slingshots