mirror of
https://github.com/owenlejeune/AirHockey.git
synced 2025-11-12 02:22:45 -05:00
Sound toggle variables combined
This commit is contained in:
12
html/game.js
12
html/game.js
@@ -15,8 +15,7 @@ const GOAL_SOUND = new Audio('ding.mp3');
|
||||
const SOUND_ICON = 'sound.png';
|
||||
const MUTE_ICON = 'mute.png';
|
||||
|
||||
var collisionSound = true;
|
||||
var goalSound = true;
|
||||
var soundEnabled = true;
|
||||
var player1 = {};
|
||||
var player2 = {};
|
||||
var puck = {}
|
||||
@@ -86,7 +85,7 @@ socket.on("playerReset", (data) => {
|
||||
});
|
||||
|
||||
socket.on("pointScored", (data) => {
|
||||
if(goalSound){GOAL_SOUND.play()};
|
||||
if(soundEnabled){GOAL_SOUND.play()};
|
||||
var receivedData = JSON.parse(data);
|
||||
puck = receivedData.puck;
|
||||
player1.score = receivedData.p1Score;
|
||||
@@ -121,7 +120,7 @@ socket.on("startGame", (data) => {
|
||||
});
|
||||
|
||||
socket.on("collision", (data) => {
|
||||
if(collisionSound){HIT_SOUND.play();}
|
||||
if(soundEnabled){HIT_SOUND.play();}
|
||||
})
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
@@ -247,7 +246,6 @@ function leaveGame(){
|
||||
}
|
||||
|
||||
function toggleSound(){
|
||||
collisionSound = (collisionSound) ? false : true;
|
||||
goalSound = (goalSound) ? false : true;
|
||||
document.getElementById('soundstate').src = (collisionSound) ? SOUND_ICON : MUTE_ICON;
|
||||
soundEnabled = (soundEnabled) ? false : true;
|
||||
document.getElementById('soundstate').src = (soundEnabled) ? SOUND_ICON : MUTE_ICON;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user