Workshop › Pinball › Step 24 of 42
A flipper is a bar that turns around a fixed pivot. Each has a pivot (x, y), a resting angle and an up angle. In
the game each flipper also has its current angle and turning speed.
```js
const FLIPPER_LENGTH = 62
const FLIPPERS = [
{ x: 130, y: 530, rest: 0.45, up: -0.45, key: 'left' },
{ x: 270, y: 530, rest: Math.PI - 0.45, up: Math.PI + 0.45, key: 'right' },
]
let flippers // { ...FLIPPERS[i], angle, speed }
flippers = FLIPPERS.map((f) => ({ ...f, angle: f.rest, speed: 0 }))
```y grows downwards, a positive angle tilts down.
The left flipper rests at 0.45 (right and down) and goes up to -0.45.Math.PI (half a turn).{ ...f, angle: f.rest, speed: 0 } copies all of f's fields into a new object and adds two more, so FLIPPERS
itself never changes. The parentheses around { } make the arrow function return the object.BUMPERS list write FLIPPER_LENGTH and FLIPPERS.let ball write let flippers.flippers = ... line the first line of reset.Skills: Game states, Arrays and objects
← Lit for a moment, points once Where is the tip? →