Skip to content

Commit

Permalink
Sound optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
blueSparrow2000 committed Jan 5, 2024
1 parent 8fcb2fe commit d055eb0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions public/js/classes/Projectile.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Projectile {
draw() {
if (this.gunName === 'CrossBow'){
c.save()
c.lineWidth = 6
c.fillStyle = 'rgb(200,200,200)'
c.beginPath()
c.arc(this.x,this.y, 10, this.startangle, this.endangle, false) // 10 is about the speed at terminal
Expand Down
4 changes: 2 additions & 2 deletions public/js/eventListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function shootProj(event){
listen = false // block

const consumeSound = frontEndConsumableSounds[currentItemName]// new Audio(`/consumeSound/${currentItemName}.mp3`)
consumeSound.cloneNode(true).play()
consumeSound.play()

// decrease amount here (if needed in future)

Expand Down Expand Up @@ -182,7 +182,7 @@ function reloadGun(){
//console.log("reloading!")

let reloadSound = frontEndGunReloadSounds[currentGunName] //new Audio(`/reloadSound/${currentGunName}.mp3`)
reloadSound.cloneNode(true).play()
reloadSound.play()
// reload ammo here!!!!!

frontEndPlayer.reloading = true
Expand Down
9 changes: 5 additions & 4 deletions public/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ socket.on('serverVars',( {gunInfo, ammoInfo, consumableInfo, PLAYERSPEED})=>{



//console.log("front end got the variables from the server")
console.log("front end got the variables from the server")
})


Expand Down Expand Up @@ -263,11 +263,12 @@ socket.on('updateFrontEnd',({backEndPlayers, backEndEnemies, backEndProjectiles,
const DISTANCE = Math.hypot(backEndProjectile.x - me.x, backEndProjectile.y - me.y)
const thatGunSoundDistance = gunInfoFrontEnd[gunName].projectileSpeed * 20
if (gunName && (DISTANCE-100 < thatGunSoundDistance) ){
let gunSound = frontEndGunSounds[gunName] //new Audio(`/sound/${gunName}.mp3`)
let gunSound = frontEndGunSounds[gunName].cloneNode(true) //new Audio(`/sound/${gunName}.mp3`)
if (DISTANCE > 100){
gunSound.volume = Math.round( 10*(thatGunSoundDistance - (DISTANCE-100))/thatGunSoundDistance ) / 10
}
gunSound.cloneNode(true).play()
gunSound.play()
gunSound.remove()
}
}

Expand Down Expand Up @@ -301,7 +302,7 @@ socket.on('updateFrontEnd',({backEndPlayers, backEndEnemies, backEndProjectiles,
const DISTANCE = Math.hypot(backendDrawable.start.x - me.x, backendDrawable.start.y - me.y)
if (DISTANCE < GUNHEARRANGE) {
let gunSound = frontEndGunSounds['railgun']// new Audio('/sound/railgun.mp3')
gunSound.cloneNode(true).play()
gunSound.play()
}
}

Expand Down

0 comments on commit d055eb0

Please sign in to comment.