Hotfix/No way to pause on mobile (#19)
- Added pause button functionality to control game state (pause/resume). - Updated sound status button visibility and styling for improved user experience. - Adjusted button styles for better responsiveness and aesthetics on mobile devices. - Implemented logic to show/hide buttons based on game state transitions. This update improves gameplay interaction and visual feedback for users. Reviewed-on: #19 Co-authored-by: Juan Sebastian Montoya <juansmm@outlook.com> Co-committed-by: Juan Sebastian Montoya <juansmm@outlook.com>
This commit is contained in:
parent
b793b83c96
commit
80b812ce1f
2 changed files with 103 additions and 7 deletions
62
index.html
62
index.html
|
|
@ -118,18 +118,57 @@
|
||||||
font-family: 'Courier New', monospace;
|
font-family: 'Courier New', monospace;
|
||||||
}
|
}
|
||||||
#soundStatus {
|
#soundStatus {
|
||||||
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 20px;
|
top: 20px;
|
||||||
right: 100px;
|
right: 90px;
|
||||||
font-size: 20px;
|
background: rgba(0,0,0,0.7);
|
||||||
|
border: 2px solid white;
|
||||||
|
color: white;
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
border-radius: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
transition: all 0.2s;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
opacity: 0.8;
|
|
||||||
transition: opacity 0.2s;
|
|
||||||
}
|
}
|
||||||
#soundStatus:hover {
|
#soundStatus:hover {
|
||||||
opacity: 1;
|
background: rgba(0,0,0,0.9);
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
#soundStatus:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
#pauseBtn {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 20px;
|
||||||
|
right: 20px;
|
||||||
|
background: rgba(0,0,0,0.7);
|
||||||
|
border: 2px solid white;
|
||||||
|
color: white;
|
||||||
|
font-size: 24px;
|
||||||
|
padding: 10px 15px;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
z-index: 100;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
#pauseBtn:hover {
|
||||||
|
background: rgba(0,0,0,0.9);
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
#pauseBtn:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
/* Show buttons when game is active */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
#pauseBtn {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#perfMonitor {
|
#perfMonitor {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|
@ -162,8 +201,15 @@
|
||||||
}
|
}
|
||||||
#soundStatus {
|
#soundStatus {
|
||||||
top: 10px;
|
top: 10px;
|
||||||
right: 60px;
|
right: 80px;
|
||||||
font-size: 18px;
|
font-size: 20px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
}
|
||||||
|
#pauseBtn {
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
font-size: 20px;
|
||||||
|
padding: 8px 12px;
|
||||||
}
|
}
|
||||||
#perfMonitor {
|
#perfMonitor {
|
||||||
top: 40px;
|
top: 40px;
|
||||||
|
|
@ -186,6 +232,8 @@
|
||||||
|
|
||||||
<div id="soundStatus" title="Sound ON (Press M to mute)">🔊</div>
|
<div id="soundStatus" title="Sound ON (Press M to mute)">🔊</div>
|
||||||
|
|
||||||
|
<button id="pauseBtn" title="Pause Game">⏸️</button>
|
||||||
|
|
||||||
<div id="perfMonitor">
|
<div id="perfMonitor">
|
||||||
<div><span class="label">FPS:</span> <span id="fps">60</span></div>
|
<div><span class="label">FPS:</span> <span id="fps">60</span></div>
|
||||||
<div><span class="label">Frame:</span> <span id="frameTime">16.7</span>ms</div>
|
<div><span class="label">Frame:</span> <span id="frameTime">16.7</span>ms</div>
|
||||||
|
|
|
||||||
|
|
@ -411,6 +411,16 @@ export class Game {
|
||||||
document.getElementById('instructions').style.display = 'block';
|
document.getElementById('instructions').style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show pause and sound buttons when game starts
|
||||||
|
const pauseBtn = document.getElementById('pauseBtn');
|
||||||
|
if (pauseBtn) {
|
||||||
|
pauseBtn.style.display = 'block';
|
||||||
|
}
|
||||||
|
const soundStatus = document.getElementById('soundStatus');
|
||||||
|
if (soundStatus) {
|
||||||
|
soundStatus.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
// Reset UI
|
// Reset UI
|
||||||
this.updateUI();
|
this.updateUI();
|
||||||
document.getElementById('combo').style.display = 'none';
|
document.getElementById('combo').style.display = 'none';
|
||||||
|
|
@ -436,6 +446,13 @@ export class Game {
|
||||||
this.soundSystem.stopBackgroundMusic();
|
this.soundSystem.stopBackgroundMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update pause button text
|
||||||
|
const pauseBtn = document.getElementById('pauseBtn');
|
||||||
|
if (pauseBtn) {
|
||||||
|
pauseBtn.textContent = '▶️';
|
||||||
|
pauseBtn.title = 'Resume Game';
|
||||||
|
}
|
||||||
|
|
||||||
if (this.uiSystem) {
|
if (this.uiSystem) {
|
||||||
this.uiSystem.setState('paused');
|
this.uiSystem.setState('paused');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -458,6 +475,13 @@ export class Game {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update pause button text
|
||||||
|
const pauseBtn = document.getElementById('pauseBtn');
|
||||||
|
if (pauseBtn) {
|
||||||
|
pauseBtn.textContent = '⏸️';
|
||||||
|
pauseBtn.title = 'Pause Game';
|
||||||
|
}
|
||||||
|
|
||||||
if (this.uiSystem) {
|
if (this.uiSystem) {
|
||||||
this.uiSystem.setState('playing');
|
this.uiSystem.setState('playing');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -476,6 +500,16 @@ export class Game {
|
||||||
this.isPaused = false;
|
this.isPaused = false;
|
||||||
this.timeScale = 0; // Stop time in menu
|
this.timeScale = 0; // Stop time in menu
|
||||||
|
|
||||||
|
// Hide pause and sound buttons when returning to menu
|
||||||
|
const pauseBtn = document.getElementById('pauseBtn');
|
||||||
|
if (pauseBtn) {
|
||||||
|
pauseBtn.style.display = 'none';
|
||||||
|
}
|
||||||
|
const soundStatus = document.getElementById('soundStatus');
|
||||||
|
if (soundStatus) {
|
||||||
|
soundStatus.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
// Update UI state
|
// Update UI state
|
||||||
if (this.uiSystem) {
|
if (this.uiSystem) {
|
||||||
this.uiSystem.setState('menu');
|
this.uiSystem.setState('menu');
|
||||||
|
|
@ -516,6 +550,20 @@ export class Game {
|
||||||
pauseMenuBtn.addEventListener('click', () => this.returnToMenu());
|
pauseMenuBtn.addEventListener('click', () => this.returnToMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pause button (for mobile)
|
||||||
|
const pauseBtn = document.getElementById('pauseBtn');
|
||||||
|
if (pauseBtn) {
|
||||||
|
pauseBtn.addEventListener('click', () => {
|
||||||
|
if (this.gameActive && !this.inMenu) {
|
||||||
|
if (this.isPaused) {
|
||||||
|
this.resumeGame();
|
||||||
|
} else {
|
||||||
|
this.pauseGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('restartBtn').addEventListener('click', () => this.restart());
|
document.getElementById('restartBtn').addEventListener('click', () => this.restart());
|
||||||
|
|
||||||
// Toggle performance monitor with 'T' key
|
// Toggle performance monitor with 'T' key
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue