From 4c046c1f5189b91530217a3cf66df8c87265016a Mon Sep 17 00:00:00 2001 From: Martin Fernandez Prieto Date: Mon, 25 Nov 2019 13:08:50 +0100 Subject: [PATCH] 0.7.2: mejorados un par de sonidos --- src/controladores/ControladorAudio.js | 18 +++++++++++++++--- src/layers/GameLayer.js | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/controladores/ControladorAudio.js b/src/controladores/ControladorAudio.js index 133ad0d..d75a774 100644 --- a/src/controladores/ControladorAudio.js +++ b/src/controladores/ControladorAudio.js @@ -2,6 +2,8 @@ class ControladorAudio { constructor() { this.comerSemillaPlaying = false; this.escapandoPlaying = false; + this.comerEnemigoPlaying = false; + this.perderPlaying = false; this.audioEscapando = new Audio(sonidos.pacman_modoEscapando); } @@ -19,7 +21,7 @@ class ControladorAudio { if(!this.escapandoPlaying) { this.escapandoPlaying = true; this.audioEscapando = new Audio(sonidos.pacman_modoEscapando); - this.audioEscapando.play(); + await this.audioEscapando.play(); } } @@ -29,7 +31,12 @@ class ControladorAudio { } async playComerEnemigo() { - new Audio(sonidos.pacman_comeEnemigo).play(); + if(!this.comerEnemigoPlaying) { + this.comerEnemigoPlaying = true; + let audio = new Audio(sonidos.pacman_comeEnemigo); + await audio.play(); + audio.onended = () => {this.comerEnemigoPlaying = false;} + } } async playComerVida() { @@ -53,6 +60,11 @@ class ControladorAudio { } async playPerder() { - new Audio(sonidos.perder).play(); + if(!this.perderPlaying) { + this.perderPlaying = true; + let audio = new Audio(sonidos.perder); + await audio.play(); + audio.onended = () => {this.perderPlaying = false;} + } } } \ No newline at end of file diff --git a/src/layers/GameLayer.js b/src/layers/GameLayer.js index 27cd38e..7d54983 100644 --- a/src/layers/GameLayer.js +++ b/src/layers/GameLayer.js @@ -115,7 +115,6 @@ class GameLayer extends Layer { this.reiniciarNivel(); if(this.controladorJuego.vidas == 0) this.perder(); - this.controladorAudio.playPerder(); return; } @@ -157,6 +156,7 @@ class GameLayer extends Layer { if (this.jugador.estado != estados.muerto && this.jugador.estado != estados.muriendo) { this.controladorJuego.vidas--; this.controladorJuego.reiniciarNivel(); + this.controladorAudio.playPerder(); } this.jugador.golpeado(); } else if(this.controladorJuego.estadoJuego === estadosJuego.enemigosEscapando) {