This commit is contained in:
Marty Killian 2023-12-07 13:45:22 +01:00
parent beef2d1519
commit 8be4120b36
5 changed files with 23 additions and 0 deletions

Binary file not shown.

BIN
assets/sounds/shoot.mp3 Normal file

Binary file not shown.

View file

@ -2,6 +2,7 @@
<html>
<head>
<script type="text/javascript" src="./js/class.js"></script>
<script type="text/javascript" src="./js/sound.js"></script>
<script type="text/javascript" src="./js/objects.js"></script>
<script type="text/javascript" src="./js/render.js"></script>
<script type="text/javascript" src="./js/input.js"></script>

View file

@ -22,6 +22,9 @@ let player = null;
Inp = new Input("canvas", Net,Renderer);
let sound = new Sound("./assets/sounds/");
sound.loadSounds()
playerId=Net.playerId;
player=Net.clientPlayer;
players=Net.getPlayersToAdd();
@ -90,7 +93,9 @@ function addBullets()
bulletsToAdd.forEach((b) => {
bullets.push(b);
Renderer.addBullet(b);
sound.shoot()
});
}
function updateBullets(dt)

17
js/sound.js Normal file
View file

@ -0,0 +1,17 @@
class Sound{
constructor(url){
this.assetsUrl = url;
}
loadSounds(){
console.log(this.assetsUrl + "shoot.mp3")
this.shootSound = new Audio(this.assetsUrl + "shoot.mp3");
this.shootSound.type = "audio/mp3";
}
shoot(){
this.shootSound.pause()
this.shootSound.currentTime=0;
this.shootSound.play()
}
}