mirror of
https://github.com/danbulant/bobek
synced 2026-06-09 09:41:40 +00:00
SFX Added
This commit is contained in:
parent
129ef1c15d
commit
91639aea8b
6 changed files with 25 additions and 3 deletions
28
game.js
28
game.js
|
|
@ -5,6 +5,7 @@
|
||||||
switch (state.curr) {
|
switch (state.curr) {
|
||||||
case state.getReady :
|
case state.getReady :
|
||||||
state.curr = state.Play;
|
state.curr = state.Play;
|
||||||
|
SFX.start.play();
|
||||||
break;
|
break;
|
||||||
case state.Play :
|
case state.Play :
|
||||||
bird.flap();
|
bird.flap();
|
||||||
|
|
@ -15,6 +16,7 @@
|
||||||
bird.y = 100;
|
bird.y = 100;
|
||||||
pipe.pipes=[];
|
pipe.pipes=[];
|
||||||
UI.score.curr = 0;
|
UI.score.curr = 0;
|
||||||
|
SFX.played=false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -28,6 +30,14 @@
|
||||||
gameOver : 2,
|
gameOver : 2,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
const SFX = {
|
||||||
|
start : new Audio(),
|
||||||
|
flap : new Audio(),
|
||||||
|
score : new Audio(),
|
||||||
|
hit : new Audio(),
|
||||||
|
die : new Audio(),
|
||||||
|
played : false
|
||||||
|
}
|
||||||
const gnd = {
|
const gnd = {
|
||||||
sprite : new Image(),
|
sprite : new Image(),
|
||||||
x : 0,
|
x : 0,
|
||||||
|
|
@ -148,6 +158,10 @@
|
||||||
this.speed = 0;
|
this.speed = 0;
|
||||||
this.y=gnd.y-r;
|
this.y=gnd.y-r;
|
||||||
this.rotatation=90;
|
this.rotatation=90;
|
||||||
|
if(!SFX.played) {
|
||||||
|
SFX.die.play();
|
||||||
|
SFX.played = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -156,7 +170,10 @@
|
||||||
},
|
},
|
||||||
flap : function(){
|
flap : function(){
|
||||||
if(this.y > 0)
|
if(this.y > 0)
|
||||||
this.speed = -this.thrust;
|
{
|
||||||
|
SFX.flap.play();
|
||||||
|
this.speed = -this.thrust;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
setRotation : function(){
|
setRotation : function(){
|
||||||
if(this.speed <= 0)
|
if(this.speed <= 0)
|
||||||
|
|
@ -183,6 +200,7 @@
|
||||||
{
|
{
|
||||||
if(this.y - r <= roof || this.y + r>= floor)
|
if(this.y - r <= roof || this.y + r>= floor)
|
||||||
{
|
{
|
||||||
|
SFX.hit.play();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,6 +208,7 @@
|
||||||
else if(pipe.moved)
|
else if(pipe.moved)
|
||||||
{
|
{
|
||||||
UI.score.curr++;
|
UI.score.curr++;
|
||||||
|
SFX.score.play();
|
||||||
pipe.moved = false;
|
pipe.moved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -256,7 +275,11 @@ bird.animations[0].sprite.src="img/bird/b0.png";
|
||||||
bird.animations[1].sprite.src="img/bird/b1.png";
|
bird.animations[1].sprite.src="img/bird/b1.png";
|
||||||
bird.animations[2].sprite.src="img/bird/b2.png";
|
bird.animations[2].sprite.src="img/bird/b2.png";
|
||||||
bird.animations[3].sprite.src="img/bird/b0.png";
|
bird.animations[3].sprite.src="img/bird/b0.png";
|
||||||
|
SFX.start.src = "sfx/start.wav"
|
||||||
|
SFX.flap.src = "sfx/flap.wav"
|
||||||
|
SFX.score.src = "sfx/score.wav"
|
||||||
|
SFX.hit.src = "sfx/hit.wav"
|
||||||
|
SFX.die.src = "sfx/die.wav"
|
||||||
|
|
||||||
gameLoop();
|
gameLoop();
|
||||||
|
|
||||||
|
|
@ -273,7 +296,6 @@ gameLoop();
|
||||||
bird.update();
|
bird.update();
|
||||||
gnd.update();
|
gnd.update();
|
||||||
pipe.update();
|
pipe.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
function draw()
|
function draw()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
BIN
sfx/die.wav
Normal file
BIN
sfx/die.wav
Normal file
Binary file not shown.
BIN
sfx/flap.wav
Normal file
BIN
sfx/flap.wav
Normal file
Binary file not shown.
BIN
sfx/hit.wav
Normal file
BIN
sfx/hit.wav
Normal file
Binary file not shown.
BIN
sfx/score.wav
Normal file
BIN
sfx/score.wav
Normal file
Binary file not shown.
BIN
sfx/start.wav
Normal file
BIN
sfx/start.wav
Normal file
Binary file not shown.
Loading…
Reference in a new issue