diff options
author | elioat <elioat@tilde.institute> | 2024-12-08 22:04:31 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-08 22:04:31 -0500 |
commit | 89a4e6e730498cac67d95952ec647f01652b86c4 (patch) | |
tree | 45f9f677bc302df1be3ef3f54ce95c76af207039 | |
parent | caaab036743d41f556d7a5c469a078cc23079d34 (diff) | |
download | tour-89a4e6e730498cac67d95952ec647f01652b86c4.tar.gz |
*
-rw-r--r-- | html/mountain/game.js | 22 |
1 files changed, 20 insertions, 2 deletions
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); |