Workshop › Breakout › Step 35 of 39
The game works; now it should feel good. When a brick breaks we will throw out a dozen tiny particles. First the
function that makes them: burst(brick).
```js
let particles
particles = []
function burst(brick) {
for (let i = 0; i < 12; i++) {
particles.push({
x: brick.x + BRICK_W / 2,
y: brick.y + BRICK_H / 2,
vx: Math.random() * 6 - 3,
vy: Math.random() * 6 - 3,
life: 30,
color: COLORS[brick.row],
})
}
}
```particles is a list that newGame() empties.burst adds 12 particles at the brick's center, each with a random velocity between -3 and 3.life: 30 means it lives 30 frames (half a second); color is the brick's color.let lives write let particles.newGame, under buildBricks(), write particles = [].buildBricks (the function) and write burst.Skills: Arrays and objects, Velocity and gravity
← Play again Break into sparks →