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 toggleBtn = document.getElementById("toggleMusic");
|
||||||
const countdownOverlay = document.getElementById("countdown-overlay");
|
const countdownOverlay = document.getElementById("countdown-overlay");
|
||||||
|
|
||||||
let musicMuted = true;
|
let musicMuted = false;
|
||||||
toggleBtn.textContent = "🔇";
|
toggleBtn.textContent = "🔊";
|
||||||
|
|
||||||
function playSFX(audio) {
|
function playSFX(audio) {
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
|
|||||||
@ -9,28 +9,21 @@ const sfxLose = document.getElementById("sfxLose");
|
|||||||
const toggleBtn = document.getElementById("toggleMusic");
|
const toggleBtn = document.getElementById("toggleMusic");
|
||||||
const overlay = document.getElementById("countdown-overlay");
|
const overlay = document.getElementById("countdown-overlay");
|
||||||
|
|
||||||
// 1. Set Default Mute (Mati)
|
let musicMuted = false;
|
||||||
let musicMuted = true;
|
toggleBtn.textContent = "🔊";
|
||||||
toggleBtn.textContent = "🔇";
|
|
||||||
|
|
||||||
// 2. SFX Jalan Terus (Tanpa Cek Mute)
|
|
||||||
function playSFX(audio) {
|
function playSFX(audio) {
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
audio.play().catch(() => {});
|
audio.play().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Listener 'initAudio' DIHAPUS
|
|
||||||
// (Supaya musik tidak nyala otomatis saat klik layar sembarangan)
|
|
||||||
|
|
||||||
toggleBtn.onclick = (e) => {
|
toggleBtn.onclick = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (musicMuted) {
|
if (musicMuted) {
|
||||||
// Nyalakan Musik
|
|
||||||
bgMusic.play();
|
bgMusic.play();
|
||||||
toggleBtn.textContent = "🔊";
|
toggleBtn.textContent = "🔊";
|
||||||
musicMuted = false;
|
musicMuted = false;
|
||||||
} else {
|
} else {
|
||||||
// Matikan Musik
|
|
||||||
bgMusic.pause();
|
bgMusic.pause();
|
||||||
toggleBtn.textContent = "🔇";
|
toggleBtn.textContent = "🔇";
|
||||||
musicMuted = true;
|
musicMuted = true;
|
||||||
|
|||||||
@ -9,8 +9,8 @@ const sfxLose = document.getElementById("sfxLose");
|
|||||||
const toggleBtn = document.getElementById("toggleMusic");
|
const toggleBtn = document.getElementById("toggleMusic");
|
||||||
const countdownOverlay = document.getElementById("countdown-overlay");
|
const countdownOverlay = document.getElementById("countdown-overlay");
|
||||||
|
|
||||||
let musicMuted = true;
|
let musicMuted = false;
|
||||||
toggleBtn.textContent = "🔇";
|
toggleBtn.textContent = "🔊";
|
||||||
|
|
||||||
function playSFX(audio) {
|
function playSFX(audio) {
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
|
|||||||
@ -1,66 +1,86 @@
|
|||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
// --- 1. LOGIKA MUSIK (FIXED) ---
|
|
||||||
const musicBtn = document.getElementById('musicBtn');
|
const musicBtn = document.getElementById('musicBtn');
|
||||||
const bgMusic = document.getElementById('bgMusic');
|
const bgMusic = document.getElementById('bgMusic');
|
||||||
|
|
||||||
if (musicBtn && bgMusic) {
|
let isMusicPlaying = false;
|
||||||
// Cek status awal: Kalau lagu pause, icon harus mute
|
musicBtn.innerText = '🔇';
|
||||||
if (bgMusic.paused) {
|
|
||||||
musicBtn.textContent = '🔇';
|
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 (isMusicPlaying) {
|
||||||
|
bgMusic.pause();
|
||||||
|
musicBtn.innerText = '🔇';
|
||||||
|
isMusicPlaying = false;
|
||||||
} else {
|
} else {
|
||||||
musicBtn.textContent = '🔊';
|
bgMusic.play();
|
||||||
|
musicBtn.innerText = '🔊';
|
||||||
|
isMusicPlaying = true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
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
|
|
||||||
bgMusic.pause();
|
|
||||||
musicBtn.textContent = '🔇';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} 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";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- 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');
|
||||||
|
|
||||||
// NAVIGATION
|
// Fungsi helper biar rapi
|
||||||
function selectStage(stage) {
|
function playClick() {
|
||||||
console.log("Pindah ke stage:", stage); // Debugging
|
sfxClick.currentTime = 0;
|
||||||
window.location.href = "gameboard-" + stage + ".php";
|
sfxClick.play().catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectStage(stage) {
|
||||||
|
playClick();
|
||||||
|
// Kasih delay dikit (300ms) biar suara 'Ceklik' kedengeran sebelum pindah
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = "gameboard-" + stage + ".php";
|
||||||
|
}, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OVERLAY CREDITS
|
|
||||||
function openCredits() {
|
function openCredits() {
|
||||||
const overlay = document.getElementById('creditsOverlay');
|
playClick();
|
||||||
if(overlay) overlay.style.display = 'flex';
|
document.getElementById('creditsOverlay').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeCredits() {
|
function closeCredits() {
|
||||||
const overlay = document.getElementById('creditsOverlay');
|
playClick();
|
||||||
if(overlay) overlay.style.display = 'none';
|
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