Compare commits
No commits in common. "3af660e56b32aad915d8039d3c015359fc9ea706" and "d62cc3c97fe26969219b6dc8e1fbab58aec4c8f7" have entirely different histories.
3af660e56b
...
d62cc3c97f
@ -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 = false;
|
let musicMuted = true;
|
||||||
toggleBtn.textContent = "🔊";
|
toggleBtn.textContent = "🔇";
|
||||||
|
|
||||||
function playSFX(audio) {
|
function playSFX(audio) {
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
|
|||||||
@ -9,21 +9,28 @@ 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");
|
||||||
|
|
||||||
let musicMuted = false;
|
// 1. Set Default Mute (Mati)
|
||||||
toggleBtn.textContent = "🔊";
|
let musicMuted = true;
|
||||||
|
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 = false;
|
let musicMuted = true;
|
||||||
toggleBtn.textContent = "🔊";
|
toggleBtn.textContent = "🔇";
|
||||||
|
|
||||||
function playSFX(audio) {
|
function playSFX(audio) {
|
||||||
audio.currentTime = 0;
|
audio.currentTime = 0;
|
||||||
|
|||||||
@ -1,86 +1,66 @@
|
|||||||
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');
|
||||||
|
|
||||||
let isMusicPlaying = false;
|
if (musicBtn && bgMusic) {
|
||||||
musicBtn.innerText = '🔇';
|
// Cek status awal: Kalau lagu pause, icon harus mute
|
||||||
|
if (bgMusic.paused) {
|
||||||
if (bgMusic) {
|
musicBtn.textContent = '🔇';
|
||||||
bgMusic.play()
|
} else {
|
||||||
.then(() => {
|
musicBtn.textContent = '🔊';
|
||||||
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', () => {
|
musicBtn.addEventListener('click', () => {
|
||||||
if (isMusicPlaying) {
|
if (bgMusic.paused) {
|
||||||
bgMusic.pause();
|
// Kalau lagi mati, nyalakan
|
||||||
musicBtn.innerText = '🔇';
|
bgMusic.play().then(() => {
|
||||||
isMusicPlaying = false;
|
musicBtn.textContent = '🔊';
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log("Browser memblokir audio:", e);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
bgMusic.play();
|
// Kalau lagi nyala, matikan
|
||||||
musicBtn.innerText = '🔊';
|
bgMusic.pause();
|
||||||
isMusicPlaying = true;
|
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";
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- INIT AUDIO CLICK ---
|
// --- FUNGSI GLOBAL (Bisa dipanggil dari onclick HTML) ---
|
||||||
// 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) {
|
function selectStage(stage) {
|
||||||
playClick();
|
console.log("Pindah ke stage:", stage); // Debugging
|
||||||
// Kasih delay dikit (300ms) biar suara 'Ceklik' kedengeran sebelum pindah
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location.href = "gameboard-" + stage + ".php";
|
window.location.href = "gameboard-" + stage + ".php";
|
||||||
}, 300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OVERLAY CREDITS
|
||||||
function openCredits() {
|
function openCredits() {
|
||||||
playClick();
|
const overlay = document.getElementById('creditsOverlay');
|
||||||
document.getElementById('creditsOverlay').style.display = 'flex';
|
if(overlay) overlay.style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeCredits() {
|
function closeCredits() {
|
||||||
playClick();
|
const overlay = document.getElementById('creditsOverlay');
|
||||||
document.getElementById('creditsOverlay').style.display = 'none';
|
if(overlay) overlay.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