Skip to content
Merged
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
20 changes: 20 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@
#name-submit:hover {
background: #5aa0e9;
}
#play-again-btn {
display: none;
margin-top: 16px;
font-size: 1em;
padding: 8px 24px;
border-radius: 8px;
border: 1px solid rgba(255,255,255,0.3);
background: transparent;
color: #fff;
cursor: pointer;
font-family: inherit;
font-weight: 600;
}
#play-again-btn:hover {
background: rgba(255,255,255,0.1);
}
#play-again-btn.visible {
display: inline-block;
}
#leaderboard-panel {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
Expand Down Expand Up @@ -337,6 +356,7 @@
<br>
<button id="name-submit">Submit</button>
</div>
<button id="play-again-btn">Play Again</button>
</div>
</div>
<div id="leaderboard-panel">
Expand Down
16 changes: 11 additions & 5 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const gameoverMessage = gameoverOverlay.querySelector('.go-message');
const nameEntry = document.getElementById('name-entry');
const nameInput = document.getElementById('name-input');
const nameSubmit = document.getElementById('name-submit');
const playAgainBtn = document.getElementById('play-again-btn');
const leaderboardPanel = document.getElementById('leaderboard-panel');
const leaderboardList = document.getElementById('leaderboard-list');
const leaderboardClose = document.getElementById('leaderboard-close');
Expand Down Expand Up @@ -162,24 +163,27 @@ function enterGameOver() {
gameoverTitle.textContent = 'GAME OVER';
gameoverScore.textContent = 'Score: ' + finalScore;

levelEl.style.display = 'none';
timerEl.style.display = 'none';
playAgainBtn.classList.remove('visible');
gameoverOverlay.classList.add('visible');

if (scoreQualifies(finalScore)) {
gameoverMessage.textContent = 'New high score!';
nameEntry.classList.add('visible');
playAgainBtn.classList.add('visible');
const savedName = loadPlayerName();
nameInput.value = savedName;
nameInput.focus();
if (savedName) {
nameInput.select();
}
} else {
gameoverMessage.textContent = '';
gameoverMessage.textContent = 'Restarting...';
nameEntry.classList.remove('visible');
playAgainBtn.classList.add('visible');
resetTimer = setTimeout(() => { exitGameOver(); }, NON_QUALIFYING_DELAY);
}

levelEl.style.display = 'none';
timerEl.style.display = 'none';
gameoverOverlay.classList.add('visible');
}

function submitScore() {
Expand All @@ -194,6 +198,7 @@ function exitGameOver() {
if (resetTimer) { clearTimeout(resetTimer); resetTimer = null; }
gameoverOverlay.classList.remove('visible');
nameEntry.classList.remove('visible');
playAgainBtn.classList.remove('visible');

resetTrack();
const config = getTrackConfig();
Expand Down Expand Up @@ -224,6 +229,7 @@ function getStartBallPosition(config) {

nameSubmit.addEventListener('click', () => { submitScore(); });
nameInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') submitScore(); });
playAgainBtn.addEventListener('click', () => { exitGameOver(); });
leaderboardBtn.addEventListener('click', () => { showLeaderboard(); });
leaderboardClose.addEventListener('click', () => { hideLeaderboard(); });
leaderboardPanel.addEventListener('click', (e) => { if (e.target === leaderboardPanel) hideLeaderboard(); });
Expand Down
19 changes: 19 additions & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ canvas { display: block; }
#name-submit:hover {
background: #5aa0e9;
}
#play-again-btn {
display: none;
margin-top: 16px;
font-size: 1em;
padding: 8px 24px;
border-radius: 8px;
border: 1px solid rgba(255,255,255,0.3);
background: transparent;
color: #fff;
cursor: pointer;
font-family: inherit;
font-weight: 600;
}
#play-again-btn:hover {
background: rgba(255,255,255,0.1);
}
#play-again-btn.visible {
display: inline-block;
}
#leaderboard-panel {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<br>
<button id="name-submit">Submit</button>
</div>
<button id="play-again-btn">Play Again</button>
</div>
</div>
<div id="leaderboard-panel">
Expand Down
8 changes: 7 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const gameoverMessage = gameoverOverlay.querySelector('.go-message');
const nameEntry = document.getElementById('name-entry');
const nameInput = document.getElementById('name-input');
const nameSubmit = document.getElementById('name-submit');
const playAgainBtn = document.getElementById('play-again-btn');
const leaderboardPanel = document.getElementById('leaderboard-panel');
const leaderboardList = document.getElementById('leaderboard-list');
const leaderboardClose = document.getElementById('leaderboard-close');
Expand Down Expand Up @@ -301,21 +302,24 @@ async function enterGameOver() {
levelEl.style.display = 'none';
timerEl.style.display = 'none';
speedEl.style.display = 'none';
playAgainBtn.classList.remove('visible');
gameoverOverlay.classList.add('visible');

const qualifies = await scoreQualifies(finalScore);
if (qualifies) {
gameoverMessage.textContent = 'New high score!';
nameEntry.classList.add('visible');
playAgainBtn.classList.add('visible');
const savedName = loadPlayerName();
nameInput.value = savedName;
nameInput.focus();
if (savedName) {
nameInput.select();
}
} else {
gameoverMessage.textContent = '';
gameoverMessage.textContent = 'Restarting...';
nameEntry.classList.remove('visible');
playAgainBtn.classList.add('visible');
resetTimer = setTimeout(() => { exitGameOver(); }, NON_QUALIFYING_DELAY);
}
}
Expand All @@ -340,6 +344,7 @@ function exitGameOver() {
if (resetTimer) { clearTimeout(resetTimer); resetTimer = null; }
gameoverOverlay.classList.remove('visible');
nameEntry.classList.remove('visible');
playAgainBtn.classList.remove('visible');

resetTrack();
const config = getTrackConfig();
Expand Down Expand Up @@ -371,6 +376,7 @@ function getStartBallPosition(config) {

nameSubmit.addEventListener('click', () => { submitScore(); });
nameInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') submitScore(); });
playAgainBtn.addEventListener('click', () => { exitGameOver(); });
leaderboardBtn.addEventListener('click', () => { showLeaderboard(); });
leaderboardClose.addEventListener('click', () => { hideLeaderboard(); });
leaderboardPanel.addEventListener('click', (e) => { if (e.target === leaderboardPanel) hideLeaderboard(); });
Expand Down
Loading