From 89a4e6e730498cac67d95952ec647f01652b86c4 Mon Sep 17 00:00:00 2001 From: elioat Date: Sun, 8 Dec 2024 22:04:31 -0500 Subject: * --- html/mountain/game.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'html/mountain') diff --git a/html/mountain/game.js b/html/mountain/game.js index 6c5737f..39fff3b 100644 --- a/html/mountain/game.js +++ b/html/mountain/game.js @@ -457,6 +457,18 @@ function killPlayer() { } } +// Try to compensate for varying viewport widths +function calculateTimeLimit(isSuper) { + const baseLimit = isSuper ? SUPER_HARD_MODE_TIME_LIMIT : HARD_MODE_TIME_LIMIT; + + if (canvas.width <= 2000) return baseLimit; + + const extraWidth = canvas.width - 2000; + const extraSeconds = Math.floor(extraWidth / 1000) * (isSuper ? 0.5 : 1); + + return baseLimit + extraSeconds; +} + function updatePlayer() { if (gameState === GAME_STATE.GAME_OVER) { if (deathAnimationTimer <= 0 && keys['Enter']) { @@ -465,7 +477,10 @@ function updatePlayer() { return; } - const timeLimit = superHardMode ? SUPER_HARD_MODE_TIME_LIMIT : HARD_MODE_TIME_LIMIT; + const timeLimit = superHardMode ? + calculateTimeLimit(true) : + calculateTimeLimit(false); + if ((hardMode || superHardMode) && Date.now() - levelStartTime > timeLimit * 1000) { killPlayer(); return; @@ -586,7 +601,10 @@ function resizeCanvas() { function draw(currentTime) { if ((hardMode || superHardMode) && gameState === GAME_STATE.PLAYING) { - const timeLimit = superHardMode ? SUPER_HARD_MODE_TIME_LIMIT : HARD_MODE_TIME_LIMIT; + const timeLimit = superHardMode ? + calculateTimeLimit(true) : + calculateTimeLimit(false); + const timeElapsed = Date.now() - levelStartTime; const timeRemaining = Math.max(0, timeLimit * 1000 - timeElapsed); const progressRatio = timeRemaining / (timeLimit * 1000); -- cgit 1.4.1-2-gfad0