Skip to content

Commit aec8099

Browse files
committed
Audio class restructured
2 parents 504f3a4 + de815d3 commit aec8099

File tree

10 files changed

+38
-92
lines changed

10 files changed

+38
-92
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ apply plugin: 'java'
66

77
sourceSets{
88
main{
9-
java.srcDir 'src'
10-
resources.srcDir 'res'
9+
java.srcDirs = ['src']
10+
resources.srcDirs = ['res']
1111
}
1212
test{
13-
java.srcDir 'test'
13+
java.srcDirs = ['test']
1414
}
1515
}
1616

res/music/small.mp3

2.16 KB
Binary file not shown.

res/sfx/smallProjectile.wav

-9.95 KB
Binary file not shown.

src/com/redomar/game/audio/AudioEffect.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/com/redomar/game/audio/AudioHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.redomar.game.audio;
22

33
import javax.sound.sampled.*;
4+
import java.io.File;
45

56

67
public class AudioHandler {
@@ -9,6 +10,23 @@ public class AudioHandler {
910
private boolean active = false;
1011

1112
public AudioHandler(String path){
13+
initiate(path);
14+
}
15+
16+
public AudioHandler(File file){
17+
try {
18+
if(file.toString() != ""){
19+
initiate(file.toString());
20+
} else {
21+
throw new NullPointerException();
22+
}
23+
} catch (NullPointerException e){
24+
System.err.println("Destination Cannot be empty");
25+
throw e;
26+
}
27+
}
28+
29+
private void initiate(String path){
1230
try{
1331
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(path));
1432
AudioFormat baseformat = audioInputStream.getFormat();

src/com/redomar/game/entities/Player.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.redomar.game.Game;
44
import com.redomar.game.InputHandler;
5-
import com.redomar.game.audio.AudioEffect;
65
import com.redomar.game.entities.efx.Swim;
76
import com.redomar.game.entities.projectiles.Medium;
87
import com.redomar.game.entities.projectiles.Projectile;

src/com/redomar/game/entities/projectiles/Small.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.redomar.game.entities.projectiles;
22

3-
import com.redomar.game.audio.AudioEffect;
3+
import com.redomar.game.audio.AudioHandler;
44
import com.redomar.game.gfx.Colours;
55
import com.redomar.game.gfx.Screen;
66
import com.redomar.game.level.LevelHandler;
77

8+
import java.io.File;
9+
810
public class Small extends Projectile{
911

1012
public static final int FIRE_RATE = 10;
13+
private static final File smallShot = new File("/music/small.mp3");
14+
private static AudioHandler smallSound;
1115

1216
public Small(LevelHandler level, int x, int y, double dir) {
1317
super(level, x, y, dir);
@@ -18,10 +22,8 @@ public Small(LevelHandler level, int x, int y, double dir) {
1822
nx = speed * Math.cos(angle);
1923
ny = speed * Math.sin(angle);
2024

21-
//smallSound.setVolume(-15);
22-
23-
AudioEffect smallSound;
24-
smallSound = new AudioEffect("/sfx/smallProjectile.wav");
25+
smallSound = new AudioHandler(smallShot);
26+
smallSound.setVolume(-15);
2527
smallSound.play();
2628
}
2729

src/com/redomar/game/menu/Menu.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.redomar.game.menu;
22

33
import com.redomar.game.Game;
4-
import com.redomar.game.audio.AudioEffect;
54
import com.redomar.game.audio.AudioHandler;
6-
import com.redomar.game.entities.Player;
75
import com.redomar.game.lib.Font;
86
import com.redomar.game.lib.Mouse;
97
import com.thehowtotutorial.splashscreen.JSplash;
@@ -24,7 +22,7 @@ public class Menu implements Runnable {
2422
private static final String NAME = "Menu";
2523

2624
private static boolean running = false;
27-
private static boolean selectedStart = false;
25+
private static boolean selectedStart = true;
2826
private static boolean selectedExit = false;
2927
private static boolean gameOver = false;
3028

@@ -49,13 +47,11 @@ public static void play() {
4947
splash.toFront();
5048
splash.requestFocus();
5149
splash.splashOn();
52-
splash.setProgress(10, "Initializing SFX");
53-
54-
splash.setProgress(30, "Loading Music");
50+
splash.setProgress(20, "Loading Music");
5551
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.mp3"));
56-
splash.setProgress(40, "Setting Volume");
52+
splash.setProgress(50, "Setting Volume");
5753
Game.getBackgroundMusic().setVolume(-20);
58-
splash.setProgress(50, "Acquiring data: Multiplayer");
54+
splash.setProgress(60, "Acquiring data: Multiplayer");
5955
Thread.sleep(125);
6056
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
6157
String multiMsg = "Sorry but multiplayer has been disabled on this version.\nIf you would like multiplayer checkout Alpha 1.6";

test/com/redomar/game/audio/AudioEffectTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/com/redomar/game/audio/AudioHandlerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ public void bgMusicExists() throws Exception {
1919
assertTrue(sfx.exists());
2020
}
2121

22+
@Test(expected = NullPointerException.class)
23+
public void expectReturnExceptionFileEmptyDir(){
24+
File empty = new File("");
25+
AudioHandler audio = new AudioHandler(empty);
26+
}
27+
2228
}

0 commit comments

Comments
 (0)