Workshop › Pool › Step 12 of 33
A cushion reflects the ball: past the left edge, put it back on the edge and flip vx. Real cushions absorb some energy,
so the bounce keeps only 80% of the speed.
```js
const BOUNCE = 0.8 // speed kept when hitting a cushion
// Cushions: reflect the velocity and lose a little speed.
if (b.x < LEFT + R) [b.x, b.vx] = [LEFT + R, -b.vx * BOUNCE]
if (b.x > RIGHT - R) [b.x, b.vx] = [RIGHT - R, -b.vx * BOUNCE]
if (b.y < TOP + R) [b.y, b.vy] = [TOP + R, -b.vy * BOUNCE]
if (b.y > BOTTOM - R) [b.y, b.vy] = [BOTTOM - R, -b.vy * BOUNCE]
```R to LEFT.[b.x, b.vx] = [LEFT + R, -b.vx * BOUNCE] sets two values in one line: the position back on the edge, and the speed
reversed and reduced.FRICTION write BOUNCE.step, inside the loop, under b.y += b.vy, write the comment and the four cushion lines.Skills: Velocity and gravity, Collision detection
← Friction Aiming and rolling →