diff options
author | elioat <elioat@tilde.institute> | 2024-12-08 10:20:47 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-12-08 10:20:47 -0500 |
commit | 6bbaa02746ac49cf4e6b1cc02df657ffb59b18ea (patch) | |
tree | b9d25e111a7c1e3081d20941ae6e0cc4b5cb4ca9 | |
parent | c85546680048d48cdedb66bce56556454d759794 (diff) | |
download | tour-6bbaa02746ac49cf4e6b1cc02df657ffb59b18ea.tar.gz |
*
-rw-r--r-- | html/mountain/game.js | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/html/mountain/game.js b/html/mountain/game.js index e6b32b3..3d09add 100644 --- a/html/mountain/game.js +++ b/html/mountain/game.js @@ -82,6 +82,9 @@ const PLATFORM_PARTICLE_SPEED = 8; const PLATFORM_PARTICLE_SIZE = 4; const PLATFORM_PARTICLE_LIFETIME = 40; +const HARD_MODE_TIME_LIMIT = 7; // seconds +const SUPER_HARD_MODE_TIME_LIMIT = 5; + let gameState = GAME_STATE.PLAYING; let level = 1; let platforms = []; @@ -426,6 +429,8 @@ function generateLevel() { platforms.push(...newPlatforms); } } + + levelStartTime = Date.now(); } function resetPlayer() { @@ -441,6 +446,7 @@ function resetPlayer() { level = 1; generateLevel(); enemies = []; + levelStartTime = Date.now(); } function killPlayer() { @@ -459,6 +465,12 @@ function updatePlayer() { return; } + const timeLimit = superHardMode ? SUPER_HARD_MODE_TIME_LIMIT : HARD_MODE_TIME_LIMIT; + if ((hardMode || superHardMode) && Date.now() - levelStartTime > timeLimit * 1000) { + killPlayer(); + return; + } + if (keys['ArrowLeft']) player.velocityX = -MOVE_SPEED; else if (keys['ArrowRight']) player.velocityX = MOVE_SPEED; else player.velocityX = 0; @@ -476,7 +488,7 @@ function updatePlayer() { player.jumpsLeft--; player.isJumping = true; - // Add particles whenever you jump + // Add particles for every jump for (let i = 0; i < PARTICLE_COUNT; i++) { particles.push(createParticle(player.x, player.y, player.velocityY)); } @@ -573,8 +585,22 @@ function resizeCanvas() { } function draw(currentTime) { - ctx.fillStyle = COLORS.BACKGROUND; - ctx.fillRect(0, 0, canvas.width, canvas.height); + if ((hardMode || superHardMode) && gameState === GAME_STATE.PLAYING) { + const timeLimit = superHardMode ? SUPER_HARD_MODE_TIME_LIMIT : HARD_MODE_TIME_LIMIT; + const timeElapsed = Date.now() - levelStartTime; + const timeRemaining = Math.max(0, timeLimit * 1000 - timeElapsed); + const progressRatio = timeRemaining / (timeLimit * 1000); + + ctx.fillStyle = COLORS.BACKGROUND; + ctx.fillRect(0, 0, canvas.width, canvas.height); + + ctx.fillStyle = 'rgba(0, 0, 0, 0.1)'; + const progressWidth = canvas.width * progressRatio; + ctx.fillRect(progressWidth, 0, canvas.width - progressWidth, canvas.height); + } else { + ctx.fillStyle = COLORS.BACKGROUND; + ctx.fillRect(0, 0, canvas.width, canvas.height); + } ctx.fillStyle = COLORS.DEADLY_BORDER; ctx.fillRect(0, 0, canvas.width - exit.size - 300, DEADLY_BORDER_HEIGHT); @@ -712,6 +738,52 @@ function updatePlatforms() { ); } +let hardMode = false; +let superHardMode = false; +let levelStartTime = 0; + +const hardModeButton = document.createElement('button'); +hardModeButton.textContent = 'Hard Mode: OFF'; +hardModeButton.style.position = 'fixed'; +hardModeButton.style.left = '10px'; +hardModeButton.style.top = '40px'; +hardModeButton.style.padding = '5px 10px'; +hardModeButton.style.backgroundColor = COLORS.PLATFORM.NORMAL; +hardModeButton.style.color = 'white'; +hardModeButton.style.border = 'none'; +hardModeButton.style.cursor = 'pointer'; +document.body.appendChild(hardModeButton); + +const superHardModeButton = document.createElement('button'); +superHardModeButton.textContent = 'Super Hard Mode: OFF'; +superHardModeButton.style.position = 'fixed'; +superHardModeButton.style.left = '10px'; +superHardModeButton.style.top = '70px'; +superHardModeButton.style.padding = '5px 10px'; +superHardModeButton.style.backgroundColor = COLORS.PLATFORM.NORMAL; +superHardModeButton.style.color = 'white'; +superHardModeButton.style.border = 'none'; +superHardModeButton.style.cursor = 'pointer'; +document.body.appendChild(superHardModeButton); + +hardModeButton.addEventListener('click', () => { + hardMode = !hardMode; + superHardMode = false; + hardModeButton.textContent = `Hard Mode: ${hardMode ? 'ON' : 'OFF'}`; + superHardModeButton.textContent = 'Super Hard Mode: OFF'; + resetPlayer(); + hardModeButton.blur(); +}); + +superHardModeButton.addEventListener('click', () => { + superHardMode = !superHardMode; + hardMode = false; + superHardModeButton.textContent = `SUPER Hard Mode: ${superHardMode ? 'ON' : 'OFF'}`; + hardModeButton.textContent = 'Hard Mode: OFF'; + resetPlayer(); + superHardModeButton.blur(); +}); + document.body.style.margin = '0'; document.body.style.overflow = 'hidden'; resizeCanvas(); |