Workshop › Breakout › Step 36 of 39
Break into sparks
What we are doing
Call burst when a brick breaks, and draw every particle as a tiny 4×4 square.
```js
burst(brick)
for (const p of particles) {
ctx.fillStyle = p.color
ctx.fillRect(p.x - 2, p.y - 2, 4, 4)
}
```
What it means
burst(brick) goes right after score += 10, so every broken brick bursts once.
p.x - 2, p.y - 2 with size 4 centers the square on the particle's position.
Your turn
- In
update, write burst(brick) under score += 10.
- In
draw, after the brick loop's closing }, leave an empty line and write the particle loop.
Skills: Drawing on a canvas
← A burst of particles Move, fall and disappear →
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