Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
21 changes: 21 additions & 0 deletions frontend/src/game/classes/BallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,20 @@ export class BallManager {
}

addBall(startX?: number) {
const audio = new Audio('/mixkit-hard-typewriter-click-1119.wav');
audio.play();
const newBall = new Ball(startX || pad(WIDTH / 2 + 13), pad(50), ballRadius, 'red', this.ctx, this.obstacles, this.sinks, (index) => {
this.balls = this.balls.filter(ball => ball !== newBall);
this.onFinish?.(index, startX)

const audioContext = new AudioContext();
const oscillator = audioContext.createOscillator();
oscillator.frequency.value = 420; // A4
oscillator.connect(audioContext.destination);
oscillator.start();
oscillator.stop(audioContext.currentTime + 0.15);

this.drawSinkOnEnd(index);
});
this.balls.push(newBall);
}
Expand Down Expand Up @@ -71,6 +82,16 @@ export class BallManager {
};
}

drawSinkOnEnd(index: number) {
const sink = this.sinks[index];
this.ctx.font='normal 13px Arial';
this.ctx.clearRect(sink.x, sink.y - sink.height / 2, sink.width - (2*obstacleRadius), sink.height);
this.ctx.fillStyle = this.getColor(index).background;
this.ctx.fillRect(sink.x, sink.y + 12.5 - sink.height / 2, sink.width - (2*obstacleRadius), sink.height);
this.ctx.fillStyle = this.getColor(index).color;
this.ctx.fillText((sink?.multiplier)?.toString() + "x", sink.x - 15 + sinkWidth / 2, sink.y);
}

draw() {
this.ctx.clearRect(0, 0, WIDTH, HEIGHT);
this.drawObstacles();
Expand Down