Added sound effects
This commit is contained in:
parent
7860ceefe9
commit
cdaf2c7023
6 changed files with 11 additions and 5 deletions
|
@ -30,9 +30,9 @@ public class GameEngine extends MouseAdapter {
|
|||
private BufferedImage sceneImage;
|
||||
|
||||
private Vector<SideScollerBackground> backgrounds;
|
||||
private Vector<AudioClip> successSounds;
|
||||
|
||||
private AudioClip themeAudioClip, jumpAudioClip;
|
||||
private final URL jumpURL= getClass().getResource("/Sounds/jump.wav");
|
||||
private AudioClip themeAudioClip;
|
||||
private final URL themeURL= getClass().getResource("/Sounds/theme.wav");
|
||||
|
||||
public GameEngine(int width, int height){
|
||||
|
@ -45,10 +45,8 @@ public class GameEngine extends MouseAdapter {
|
|||
this.pWidth = width;
|
||||
this.pHeight = height;
|
||||
try {
|
||||
jumpAudioClip = Applet.newAudioClip(jumpURL);
|
||||
themeAudioClip = Applet.newAudioClip(themeURL);
|
||||
}catch (Exception e){
|
||||
jumpAudioClip = null;
|
||||
themeAudioClip = null;
|
||||
}
|
||||
|
||||
|
@ -56,6 +54,7 @@ public class GameEngine extends MouseAdapter {
|
|||
themeAudioClip.loop();
|
||||
r = new Random();
|
||||
sceneImage = new BufferedImage(width, height, Image.SCALE_SMOOTH);
|
||||
loadSuccessSounds();
|
||||
startNewGame();
|
||||
|
||||
|
||||
|
@ -88,6 +87,13 @@ public class GameEngine extends MouseAdapter {
|
|||
|
||||
}
|
||||
|
||||
private void loadSuccessSounds(){
|
||||
successSounds = new Vector<>();
|
||||
for (int i = 1 ; i < 5 ; i++){
|
||||
successSounds.add(Applet.newAudioClip(getClass().getResource("/Sounds/pass"+i+".wav")));
|
||||
}
|
||||
}
|
||||
|
||||
private void initBackgrounds(){
|
||||
backgrounds.add(new SideScollerBackground(pWidth, pHeight, 2, "skyLine.png", pWidth, pHeight));
|
||||
backgrounds.add(new SideScollerBackground(pWidth, pHeight, 5, "trees.png", pWidth + 50, pHeight));
|
||||
|
@ -172,6 +178,7 @@ public class GameEngine extends MouseAdapter {
|
|||
if(canScore && !pipes.isEmpty() && bird.getLocX() >= pipes.elementAt(0).getLocX() + pipes.elementAt(0).getSWidth()) {
|
||||
score++;
|
||||
canScore = false;
|
||||
successSounds.elementAt(r.nextInt(5)).play();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -224,7 +231,6 @@ public class GameEngine extends MouseAdapter {
|
|||
initGame();
|
||||
} else {
|
||||
bird.jump();
|
||||
jumpAudioClip.play();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
BIN
src/Sounds/pass1.wav
Normal file
BIN
src/Sounds/pass1.wav
Normal file
Binary file not shown.
BIN
src/Sounds/pass2.wav
Normal file
BIN
src/Sounds/pass2.wav
Normal file
Binary file not shown.
BIN
src/Sounds/pass3.wav
Normal file
BIN
src/Sounds/pass3.wav
Normal file
Binary file not shown.
BIN
src/Sounds/pass4.wav
Normal file
BIN
src/Sounds/pass4.wav
Normal file
Binary file not shown.
Loading…
Reference in a new issue