Skip to content

Commit 83fd61a

Browse files
committed
Added sounds and soundtracks.
1 parent a00fa82 commit 83fd61a

File tree

9 files changed

+29
-2
lines changed

9 files changed

+29
-2
lines changed

android/assets/sound/explosion.wav

43.8 KB
Binary file not shown.

android/assets/sound/shoot1.wav

22.8 KB
Binary file not shown.

android/assets/sound/shoot2.wav

31.6 KB
Binary file not shown.

android/assets/sound/shoot3.wav

27.2 KB
Binary file not shown.

android/assets/sound/shoot4.wav

42.1 KB
Binary file not shown.
6.49 MB
Binary file not shown.

core/src/ga/gussio/ld38/earthinvaders/entities/Meteorite.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ga.gussio.ld38.earthinvaders.entities;
22

33
import com.badlogic.gdx.Gdx;
4+
import com.badlogic.gdx.audio.Sound;
45
import com.badlogic.gdx.graphics.Color;
56
import com.badlogic.gdx.graphics.Texture;
67
import com.badlogic.gdx.graphics.g2d.Sprite;
@@ -28,9 +29,12 @@ public class Meteorite extends Entity {
2829
private Rectangle warningRect;
2930
private long warningTime;
3031
private Sprite[] img, warning;
32+
private Sound sound;
3133

32-
public Meteorite(Sprite[] textures, Sprite[] warning) {
34+
public Meteorite(Sprite[] textures, Sprite[] warning, Sound sound) {
3335
super(0, 0);
36+
this.sound = sound;
37+
3438
Random r = new Random();
3539
int direction = r.nextInt(360+1);
3640
health = r.nextInt(2)+3;
@@ -110,5 +114,6 @@ public void destroy(){
110114
GameScreen.entities.add(new Explosion((int) collision.getXCenter(),
111115
(int) collision.getYCenter()));
112116
GameScreen.entities.remove(this);
117+
sound.play(0.6f);
113118
}
114119
}

core/src/ga/gussio/ld38/earthinvaders/entities/Player.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ga.gussio.ld38.earthinvaders.entities;
22

33
import com.badlogic.gdx.Gdx;
4+
import com.badlogic.gdx.audio.Sound;
45
import com.badlogic.gdx.graphics.Color;
56
import com.badlogic.gdx.graphics.Texture;
67
import com.badlogic.gdx.graphics.g2d.Sprite;
@@ -24,11 +25,17 @@ public class Player extends Entity {
2425

2526
private Sprite img;
2627

28+
private Sound[] shoot;
29+
2730
public Player() {
2831
super(0, 0);
2932
this.x = (float) (GameScreen.earth.getXCenter() + radius*Math.sin(angle));
3033
this.y = (float) (GameScreen.earth.getYCenter() + radius*Math.cos(angle));
3134
img = new Sprite(new Texture(Gdx.files.internal("player.png")));
35+
shoot = new Sound[4];
36+
for(int i = 1; i <= shoot.length; i++){
37+
shoot[i-1] = Gdx.audio.newSound(Gdx.files.internal("sound/shoot"+i+".wav"));
38+
}
3239
}
3340

3441
@Override
@@ -57,6 +64,8 @@ public void shoot(){
5764
if(shootInterval == maxShootInterval){
5865
GameScreen.entities.add(new Bullet(Game.WIDTH/2, Game.HEIGHT/2, angle));
5966
shootInterval--;
67+
Random r = new Random();
68+
shoot[r.nextInt(3)+1].play(0.6f);
6069
}
6170
}
6271

core/src/ga/gussio/ld38/earthinvaders/screen/GameScreen.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ga.gussio.ld38.earthinvaders.screen;
22

33
import com.badlogic.gdx.Gdx;
4+
import com.badlogic.gdx.audio.Music;
5+
import com.badlogic.gdx.audio.Sound;
46
import com.badlogic.gdx.files.FileHandle;
57
import com.badlogic.gdx.graphics.Color;
68
import com.badlogic.gdx.graphics.OrthographicCamera;
@@ -54,6 +56,9 @@ public class GameScreen extends Screen implements InputListener {
5456
private int scoreTimer = 0;
5557
private boolean appliedScore = false;
5658

59+
private Music soundtrack;
60+
private Sound meteorDestroySound;
61+
5762
public GameScreen() {
5863
entities.clear();
5964
camera = new OrthographicCamera();
@@ -86,6 +91,11 @@ public GameScreen() {
8691
exit = new Button(1230, 450, "buttons/exit.png");
8792
retry = new Button(500, 450, "buttons/retry.png");
8893

94+
soundtrack = Gdx.audio.newMusic(Gdx.files.internal("sound/soundtrack.wav"));
95+
meteorDestroySound = Gdx.audio.newSound(Gdx.files.internal("sound/explosion.wav"));
96+
97+
soundtrack.setLooping(true);
98+
soundtrack.play();
8999
//generating randomized background
90100
Random r = new Random();
91101
background = new Particle[r.nextInt(55-45)+45];
@@ -182,7 +192,7 @@ else if (rightButton.clicked)
182192
}
183193

184194
if (System.currentTimeMillis() > spawnTimer) {
185-
entities.add(new Meteorite(meteoriteSprites, warningSprites));
195+
entities.add(new Meteorite(meteoriteSprites, warningSprites, meteorDestroySound));
186196
long dtime = System.currentTimeMillis() - startTime;
187197
if (dtime > 10000) {
188198
startTime = System.currentTimeMillis();
@@ -224,6 +234,9 @@ public void dispose() {
224234
health = maxHealth;
225235
score = 0;
226236
dmgAnimation = 0;
237+
soundtrack.stop();
238+
soundtrack.dispose();
239+
meteorDestroySound.dispose();
227240
}
228241

229242
public static void damageEarth(int hits){

0 commit comments

Comments
 (0)