-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirework.js
More file actions
33 lines (29 loc) · 878 Bytes
/
firework.js
File metadata and controls
33 lines (29 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { makeBall } from "./ball.js";
import { randomColor } from "./colors.js";
import { randomBetween } from "./helpers.js";
export const makeFirework = (canvasManager, audioManager) => {
const baseBall = makeBall(
canvasManager,
{
startPosition: {
x: randomBetween(0, canvasManager.getWidth()),
y: canvasManager.getHeight(),
},
startVelocity: { x: randomBetween(-1, 1), y: randomBetween(-8, -10) },
radius: randomBetween(6, 14),
fill: randomColor(),
delay: randomBetween(0, 1200),
},
() => {},
() => {}
);
const draw = (deltaTime) => {
if (!baseBall.isPopped() && baseBall.getVelocity().y > 1) {
// Give fireworks pops a downwards trajectory
baseBall.pop({ x: 0, y: 2 });
audioManager.playSequentialPluck();
}
baseBall.draw(deltaTime);
};
return { draw };
};