Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
lewdry committed Oct 11, 2024
1 parent a6cc19a commit c5840cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 23 additions & 4 deletions bonk.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ function initGame() {
return;
}

window.addEventListener('resize', () => {
resizeCanvas();
resetGame();
});
resetGame();

document.addEventListener('pointerdown', handleStart, false);
Expand Down Expand Up @@ -322,6 +318,29 @@ function resumeAudioContext() {
let lastHiddenTime = 0;
const HIDDEN_THRESHOLD = 5000; // 5 seconds

// Handle window resizing
function handleResize() {
const oldWidth = canvas.width;
const oldHeight = canvas.height;

resizeCanvas();

const widthRatio = canvas.width / oldWidth;
const heightRatio = canvas.height / oldHeight;

balls.forEach(ball => {
ball.x *= widthRatio;
ball.y *= heightRatio;
ball.dx *= widthRatio;
ball.dy *= heightRatio;
});
}

window.addEventListener('resize', () => {
handleResize();
separateOverlappingBalls();
});

function handleVisibilityChange() {
if (document.hidden) {
lastHiddenTime = Date.now();
Expand Down
1 change: 0 additions & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ canvas {
border: 2px solid black;
border-radius: 10px;
padding: 20px;
/* remove this pointer-events: auto; */
}

0 comments on commit c5840cf

Please sign in to comment.