Compare commits
2 Commits
d62cc3c97f
...
3af660e56b
| Author | SHA1 | Date | |
|---|---|---|---|
| 3af660e56b | |||
| 488a5bd900 |
@ -9,8 +9,8 @@ const sfxLose = document.getElementById("sfxLose");
|
||||
const toggleBtn = document.getElementById("toggleMusic");
|
||||
const countdownOverlay = document.getElementById("countdown-overlay");
|
||||
|
||||
let musicMuted = true;
|
||||
toggleBtn.textContent = "🔇";
|
||||
let musicMuted = false;
|
||||
toggleBtn.textContent = "🔊";
|
||||
|
||||
function playSFX(audio) {
|
||||
audio.currentTime = 0;
|
||||
|
||||
@ -9,28 +9,21 @@ const sfxLose = document.getElementById("sfxLose");
|
||||
const toggleBtn = document.getElementById("toggleMusic");
|
||||
const overlay = document.getElementById("countdown-overlay");
|
||||
|
||||
// 1. Set Default Mute (Mati)
|
||||
let musicMuted = true;
|
||||
toggleBtn.textContent = "🔇";
|
||||
let musicMuted = false;
|
||||
toggleBtn.textContent = "🔊";
|
||||
|
||||
// 2. SFX Jalan Terus (Tanpa Cek Mute)
|
||||
function playSFX(audio) {
|
||||
audio.currentTime = 0;
|
||||
audio.play().catch(() => {});
|
||||
}
|
||||
|
||||
// 3. Listener 'initAudio' DIHAPUS
|
||||
// (Supaya musik tidak nyala otomatis saat klik layar sembarangan)
|
||||
|
||||
toggleBtn.onclick = (e) => {
|
||||
e.stopPropagation();
|
||||
if (musicMuted) {
|
||||
// Nyalakan Musik
|
||||
bgMusic.play();
|
||||
toggleBtn.textContent = "🔊";
|
||||
musicMuted = false;
|
||||
} else {
|
||||
// Matikan Musik
|
||||
bgMusic.pause();
|
||||
toggleBtn.textContent = "🔇";
|
||||
musicMuted = true;
|
||||
|
||||
@ -9,8 +9,8 @@ const sfxLose = document.getElementById("sfxLose");
|
||||
const toggleBtn = document.getElementById("toggleMusic");
|
||||
const countdownOverlay = document.getElementById("countdown-overlay");
|
||||
|
||||
let musicMuted = true;
|
||||
toggleBtn.textContent = "🔇";
|
||||
let musicMuted = false;
|
||||
toggleBtn.textContent = "🔊";
|
||||
|
||||
function playSFX(audio) {
|
||||
audio.currentTime = 0;
|
||||
|
||||
@ -1,66 +1,86 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// --- 1. LOGIKA MUSIK (FIXED) ---
|
||||
const musicBtn = document.getElementById('musicBtn');
|
||||
const bgMusic = document.getElementById('bgMusic');
|
||||
|
||||
if (musicBtn && bgMusic) {
|
||||
// Cek status awal: Kalau lagu pause, icon harus mute
|
||||
if (bgMusic.paused) {
|
||||
musicBtn.textContent = '🔇';
|
||||
} else {
|
||||
musicBtn.textContent = '🔊';
|
||||
let isMusicPlaying = false;
|
||||
musicBtn.innerText = '🔇';
|
||||
|
||||
if (bgMusic) {
|
||||
bgMusic.play()
|
||||
.then(() => {
|
||||
console.log("Auto-play sukses");
|
||||
isMusicPlaying = true;
|
||||
musicBtn.innerText = '🔊';
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Auto-play diblokir browser, menunggu klik user.");
|
||||
isMusicPlaying = false;
|
||||
musicBtn.innerText = '🔇';
|
||||
});
|
||||
}
|
||||
|
||||
musicBtn.addEventListener('click', () => {
|
||||
if (bgMusic.paused) {
|
||||
// Kalau lagi mati, nyalakan
|
||||
bgMusic.play().then(() => {
|
||||
musicBtn.textContent = '🔊';
|
||||
}).catch((e) => {
|
||||
console.log("Browser memblokir audio:", e);
|
||||
});
|
||||
} else {
|
||||
// Kalau lagi nyala, matikan
|
||||
if (isMusicPlaying) {
|
||||
bgMusic.pause();
|
||||
musicBtn.textContent = '🔇';
|
||||
}
|
||||
});
|
||||
musicBtn.innerText = '🔇';
|
||||
isMusicPlaying = false;
|
||||
} else {
|
||||
console.error("Element Audio/Tombol tidak ditemukan!");
|
||||
}
|
||||
|
||||
// --- 2. LOGOUT ---
|
||||
const logoutBtn = document.getElementById("logoutBtn");
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener("click", () => {
|
||||
window.location.href = "logout.php";
|
||||
});
|
||||
}
|
||||
|
||||
// --- 3. LEADERBOARD ---
|
||||
const leaderboardBtn = document.getElementById("leaderboardBtn");
|
||||
if (leaderboardBtn) {
|
||||
leaderboardBtn.addEventListener("click", () => {
|
||||
window.location.href = "Leaderboard.php";
|
||||
});
|
||||
bgMusic.play();
|
||||
musicBtn.innerText = '🔊';
|
||||
isMusicPlaying = true;
|
||||
}
|
||||
});
|
||||
|
||||
// --- FUNGSI GLOBAL (Bisa dipanggil dari onclick HTML) ---
|
||||
});
|
||||
|
||||
// --- INIT AUDIO CLICK ---
|
||||
// Pastikan path-nya sesuai dengan folder kamu
|
||||
const sfxClick = new Audio('music/music-click.mp3');
|
||||
|
||||
// Fungsi helper biar rapi
|
||||
function playClick() {
|
||||
sfxClick.currentTime = 0;
|
||||
sfxClick.play().catch(() => {});
|
||||
}
|
||||
|
||||
// NAVIGATION
|
||||
function selectStage(stage) {
|
||||
console.log("Pindah ke stage:", stage); // Debugging
|
||||
playClick();
|
||||
// Kasih delay dikit (300ms) biar suara 'Ceklik' kedengeran sebelum pindah
|
||||
setTimeout(() => {
|
||||
window.location.href = "gameboard-" + stage + ".php";
|
||||
}, 300);
|
||||
}
|
||||
|
||||
// OVERLAY CREDITS
|
||||
function openCredits() {
|
||||
const overlay = document.getElementById('creditsOverlay');
|
||||
if(overlay) overlay.style.display = 'flex';
|
||||
playClick();
|
||||
document.getElementById('creditsOverlay').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeCredits() {
|
||||
const overlay = document.getElementById('creditsOverlay');
|
||||
if(overlay) overlay.style.display = 'none';
|
||||
playClick();
|
||||
document.getElementById('creditsOverlay').style.display = 'none';
|
||||
}
|
||||
|
||||
// Untuk Logout
|
||||
const logoutBtn = document.getElementById("logoutBtn");
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener("click", (e) => {
|
||||
e.preventDefault(); // Tahan dulu biar gak langsung pindah
|
||||
playClick();
|
||||
setTimeout(() => {
|
||||
window.location.href = "logout.php";
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
// Untuk Leaderboard
|
||||
const leaderboardBtn = document.getElementById("leaderboardBtn");
|
||||
if (leaderboardBtn) {
|
||||
leaderboardBtn.addEventListener("click", (e) => {
|
||||
e.preventDefault(); // Tahan dulu
|
||||
playClick();
|
||||
setTimeout(() => {
|
||||
window.location.href = "Leaderboard.php";
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user