From 8fcb2fe8d8f13925035276772cf21bb301815896 Mon Sep 17 00:00:00 2001 From: blueSparrow2000 Date: Fri, 5 Jan 2024 16:39:51 +0900 Subject: [PATCH] Sound update: optimization --- backend.js | 12 ++++---- gun informations.xlsx | Bin 0 -> 11270 bytes public/js/classes/Player.js | 2 +- public/js/eventListeners.js | 10 +++---- public/js/frontend.js | 55 ++++++++++++++++++++++++++---------- 5 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 gun informations.xlsx diff --git a/backend.js b/backend.js index 8b2b066..aeafaab 100644 --- a/backend.js +++ b/backend.js @@ -10,7 +10,7 @@ const PLAYERRADIUS = 10 //16 const PLAYERSPEED = TICKRATE/5 // pixel const PLAYERHEALTH = 3 const PLAYERHEALTHMAX = 6 -const GUNHEARRANGE = 500 +const GUNHEARRANGE = 700 const PLAYER_JOIN_DELAY = 3000 //to check if there exists any player left @@ -42,10 +42,10 @@ const gunInfo = { 'railgun':{travelDistance:0, damage: 3, shake:0, num: 1, fireRate: 1000, projectileSpeed:0, magSize:2, reloadTime: 1800, ammotype:'battery', size: {length:50, width:5}}, // pierce walls and entities 'CrossBow':{travelDistance:650, damage: 15, shake:0, num: 1, fireRate: 100, projectileSpeed:10, magSize: 1, reloadTime: 1300, ammotype:'bolt', size: {length:21, width:2}}, -'M1':{travelDistance:2400, damage: 6, shake:0, num: 1, fireRate: 1600, projectileSpeed:42, magSize: 5, reloadTime: 4000, ammotype:'7mm', size: {length:42, width:4}}, -'mk14':{travelDistance:1600, damage: 3, shake:1, num: 1, fireRate: 600, projectileSpeed:32, magSize:14, reloadTime: 3300, ammotype:'7mm', size: {length:32, width:3} }, -'SLR':{travelDistance:2000, damage: 3.5, shake:1, num: 1, fireRate: 350, projectileSpeed:36, magSize: 10, reloadTime: 2700, ammotype:'7mm', size: {length:38, width:3}}, -'AWM':{travelDistance:3000, damage: 12, shake:0, num: 1, fireRate: 2000, projectileSpeed:30, magSize: 7, reloadTime: 4000, ammotype:'7mm', size: {length:50, width:5}}, +'M1':{travelDistance:2000, damage: 6, shake:0, num: 1, fireRate: 1600, projectileSpeed:42, magSize: 5, reloadTime: 4000, ammotype:'7mm', size: {length:42, width:4}}, +'mk14':{travelDistance:1000, damage: 3, shake:1, num: 1, fireRate: 600, projectileSpeed:32, magSize:14, reloadTime: 3300, ammotype:'7mm', size: {length:32, width:3} }, +'SLR':{travelDistance:1200, damage: 3.5, shake:1, num: 1, fireRate: 350, projectileSpeed:36, magSize: 10, reloadTime: 2700, ammotype:'7mm', size: {length:38, width:3}}, +'AWM':{travelDistance:2400, damage: 12, shake:0, num: 1, fireRate: 2000, projectileSpeed:30, magSize: 7, reloadTime: 4000, ammotype:'7mm', size: {length:50, width:5}}, 'pistol':{travelDistance:400, damage: 1, shake:3, num: 1, fireRate: 300, projectileSpeed:20, magSize:15, reloadTime: 1100, ammotype:'5mm', size: {length:17, width:2}}, 'M249':{travelDistance:800, damage: 1, shake:1, num: 1, fireRate: 75, projectileSpeed:28, magSize:150, reloadTime: 7400, ammotype:'5mm', size: {length:28, width:6}}, @@ -495,7 +495,7 @@ io.on('connection', (socket) => { console.log('a user connected'); // give server info to a frontend - socket.emit('serverVars', {gunInfo, ammoInfo, PLAYERSPEED}) + socket.emit('serverVars', {gunInfo, ammoInfo, consumableInfo, PLAYERSPEED}) // projectile spawn socket.on('shoot',({x,y,angle, mousePos, currentGun,playerIdEXACT}) => { diff --git a/gun informations.xlsx b/gun informations.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..648b01b51c5275f63fec995ee7c3726f4aed2a93 GIT binary patch literal 11270 zcmeHtg;$)(()Zv)uo>KfYtZ2C?w;TY?he5%Sb*S?2@b(ESa5>7LvWYi1b6r*`F79l zX7BqK+}nLl_cLd@>N!t${i>>~N<|(H9vgrN00IC2a)8lcnuP%j01yKY0AK-tu)5;* zb}puNE`}N&4yMlf%Fv%@ciU2te z0(&r@sS17VjPEWo)=jsxd`y3L3lhu1vEu%WIkMozc06QJX=hs-7}njWh8hvj`&H9` zh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/Player.js +++ b/public/js/classes/Player.js @@ -92,7 +92,7 @@ class Player { c.lineWidth = bodywidth c.stroke() - } else if(thisguninfo.travelDistance >= 1200){ // snipters except VSS (can shoot all across the screen) + } else if(thisguninfo.projectileSpeed >= 30){ // snipters except VSS (can shoot all across the screen) const tipsize = 3 const tipstart = itemlength- tipsize const tipwidth = itemSize.width + thisguninfo.damage/3 diff --git a/public/js/eventListeners.js b/public/js/eventListeners.js index 2565dfb..5758ebd 100644 --- a/public/js/eventListeners.js +++ b/public/js/eventListeners.js @@ -39,8 +39,8 @@ function shootProj(event){ if (!listen) {return} // not ready to eat listen = false // block - let consumeSound = new Audio(`/consumeSound/${currentItemName}.mp3`) - consumeSound.play() + const consumeSound = frontEndConsumableSounds[currentItemName]// new Audio(`/consumeSound/${currentItemName}.mp3`) + consumeSound.cloneNode(true).play() // decrease amount here (if needed in future) @@ -181,8 +181,8 @@ function reloadGun(){ listen = false // block //console.log("reloading!") - let gunSound = new Audio(`/reloadSound/${currentGunName}.mp3`) - gunSound.play() + let reloadSound = frontEndGunReloadSounds[currentGunName] //new Audio(`/reloadSound/${currentGunName}.mp3`) + reloadSound.cloneNode(true).play() // reload ammo here!!!!! frontEndPlayer.reloading = true @@ -247,7 +247,7 @@ function interactItem(itemId,backEndItems){ listen = false //console.log("interacting!") - let interactSound = new Audio("/sound/interact.mp3") + interactSound.play() // interact here! diff --git a/public/js/frontend.js b/public/js/frontend.js index 1345eed..72a732f 100644 --- a/public/js/frontend.js +++ b/public/js/frontend.js @@ -5,8 +5,17 @@ const TICKRATE = 15 const gunInfoFrontEnd = {} let gunInfoKeysFrontEnd = [] +let frontEndGunSounds = {} +let frontEndGunReloadSounds = {} + const ammoInfoFrontEnd = {} let ammoInfoKeysFrontEnd = [] +const interactSound = new Audio("/sound/interact.mp3") + +let frontEndConsumableSounds = {} +let consumableInfoKeysFrontEnd = [] + + const SCREENWIDTH = 1024//1920// const SCREENHEIGHT = 576//1080// @@ -23,9 +32,9 @@ let listen = true // very important for event listener // initialize server variables -socket.on('serverVars',( {gunInfo, ammoInfo, PLAYERSPEED})=>{ +socket.on('serverVars',( {gunInfo, ammoInfo, consumableInfo, PLAYERSPEED})=>{ PLAYERSPEEDFRONTEND = PLAYERSPEED - + // ammo infos ammoInfoKeysFrontEnd = Object.keys(ammoInfo) for (let i=0;i{ } //console.log(ammoInfoFrontEnd) + // gun infos gunInfoKeysFrontEnd = Object.keys(gunInfo) //console.log(gunInfoKeysFrontEnd[0]) for (let i=0;i 100){ + gunSound.volume = Math.round( 10*(thatGunSoundDistance - (DISTANCE-100))/thatGunSoundDistance ) / 10 } + gunSound.cloneNode(true).play() } } @@ -251,7 +276,7 @@ socket.on('updateFrontEnd',({backEndPlayers, backEndEnemies, backEndProjectiles, gsap.to(frontEndProjectiles[id], { x: backEndProjectile.x + backEndProjectile.velocity.x, y: backEndProjectile.y + backEndProjectile.velocity.y, - duration: 0.015, + duration: 0.015, // tick ease: 'linear' }) } @@ -275,8 +300,8 @@ socket.on('updateFrontEnd',({backEndPlayers, backEndEnemies, backEndProjectiles, if (me){ const DISTANCE = Math.hypot(backendDrawable.start.x - me.x, backendDrawable.start.y - me.y) if (DISTANCE < GUNHEARRANGE) { - let gunSound = new Audio('/sound/railgun.mp3') - gunSound.play() + let gunSound = frontEndGunSounds['railgun']// new Audio('/sound/railgun.mp3') + gunSound.cloneNode(true).play() } }