Skip to content

Commit 7ada410

Browse files
committed
Merge branch 'unitTesting' into develop
2 parents 437d9d8 + 6cf259a commit 7ada410

File tree

6 files changed

+70
-17
lines changed

6 files changed

+70
-17
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
*/
88
public class AudioEffect{
99

10-
Clip clip;
10+
private Clip clip;
11+
private boolean active = false;
1112

1213
public AudioEffect(String path){
13-
try {
14+
try{
1415
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream(path));
1516
AudioFormat baseformat = audioInputStream.getFormat();
1617
AudioInputStream decodedAudioInputStream = AudioSystem.getAudioInputStream(
@@ -27,6 +28,7 @@ public void play(){
2728
stop();
2829
clip.setFramePosition(0);
2930
clip.start();
31+
active = true;
3032
}
3133

3234
public void setVolume(float velocity){
@@ -37,10 +39,16 @@ public void setVolume(float velocity){
3739

3840
public void stop() {
3941
if (clip.isRunning()) clip.stop();
42+
active = false;
4043
}
4144

4245
public void close(){
4346
stop();
4447
clip.close();
4548
}
46-
}
49+
50+
public boolean getActive(){
51+
return this.active;
52+
}
53+
54+
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class Player extends Mob {
2929
private int[] swimColour;
3030
private int fireRate = 0;
3131

32-
private static AudioEffect shootSound;
33-
3432
public Player(LevelHandler level, int x, int y, InputHandler input,
3533
String userName, int shirtCol, int faceCol) {
3634
super(level, "Player", x, y, speed, collisionBoders);
@@ -75,8 +73,6 @@ public void tick() {
7573
if(fireRate <= 0){
7674
if(Game.getMouse().getButton()== 1){
7775
fireRate = Small.FIRE_RATE;
78-
shootSound.setVolume(-15);
79-
shootSound.play();
8076
}else if(Game.getMouse().getButton() == 3){
8177
fireRate = Medium.FIRE_RATE;
8278
}
@@ -207,14 +203,6 @@ public void render(Screen screen) {
207203
}
208204
}
209205

210-
public static AudioEffect getShootSound() {
211-
return shootSound;
212-
}
213-
214-
public static void setShootSound(AudioEffect shootSound) {
215-
Player.shootSound = shootSound;
216-
}
217-
218206
public String getUsername() {
219207
if (this.userName.isEmpty()) {
220208
return guestPlayerName;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.redomar.game.entities.projectiles;
22

3+
import com.redomar.game.audio.AudioEffect;
34
import com.redomar.game.gfx.Colours;
45
import com.redomar.game.gfx.Screen;
56
import com.redomar.game.level.LevelHandler;
67

78
public class Small extends Projectile{
89

9-
public static final int FIRE_RATE = 7;
10+
public static final int FIRE_RATE = 10;
1011

1112
public Small(LevelHandler level, int x, int y, double dir) {
1213
super(level, x, y, dir);
@@ -16,6 +17,12 @@ public Small(LevelHandler level, int x, int y, double dir) {
1617

1718
nx = speed * Math.cos(angle);
1819
ny = speed * Math.sin(angle);
20+
21+
//smallSound.setVolume(-15);
22+
23+
AudioEffect smallSound;
24+
smallSound = new AudioEffect("/sfx/smallProjectile.wav");
25+
smallSound.play();
1926
}
2027

2128
public void tick() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void play() {
5050
splash.requestFocus();
5151
splash.splashOn();
5252
splash.setProgress(10, "Initializing SFX");
53-
Player.setShootSound( new AudioEffect("/sfx/smallProjectile.wav"));
53+
5454
splash.setProgress(30, "Loading Music");
5555
Game.setBackgroundMusic(new AudioHandler("/music/Towards The End.mp3"));
5656
splash.setProgress(40, "Setting Volume");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.redomar.game.audio;
2+
3+
import org.junit.Test;
4+
5+
import java.io.File;
6+
7+
import static org.junit.Assert.*;
8+
9+
/**
10+
* Created by Mohamed on 28/08/2016.
11+
* This file tests the com.redomar.game.audio class
12+
*/
13+
public class AudioEffectTest {
14+
15+
@Test
16+
public void playSoundEffectAndSetVolume() {
17+
AudioHandler sound = new AudioHandler("/sfx/smallProjectile.wav");
18+
sound.setVolume(-15);
19+
sound.play();
20+
}
21+
22+
@Test
23+
public void sfxFileExists() throws Exception {
24+
File sfx = new File("res/sfx/smallProjectile.wav");
25+
assertTrue(sfx.exists());
26+
}
27+
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.redomar.game.audio;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import java.io.File;
7+
8+
import static org.junit.Assert.*;
9+
10+
/**
11+
* Created by Mohamed on 28/08/2016.
12+
* This file tests the com.redomar.game.audio.AudioHandler class
13+
*/
14+
public class AudioHandlerTest {
15+
16+
@Test
17+
public void bgMusicExists() throws Exception {
18+
File sfx = new File("res/music/Towards The End.mp3");
19+
assertTrue(sfx.exists());
20+
}
21+
22+
}

0 commit comments

Comments
 (0)