Skip to content

Commit

Permalink
Added sounds and soundtracks.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGussio committed Jun 18, 2017
1 parent a00fa82 commit 83fd61a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 2 deletions.
Binary file added android/assets/sound/explosion.wav
Binary file not shown.
Binary file added android/assets/sound/shoot1.wav
Binary file not shown.
Binary file added android/assets/sound/shoot2.wav
Binary file not shown.
Binary file added android/assets/sound/shoot3.wav
Binary file not shown.
Binary file added android/assets/sound/shoot4.wav
Binary file not shown.
Binary file added android/assets/sound/soundtrack.wav
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ga.gussio.ld38.earthinvaders.entities;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
Expand Down Expand Up @@ -28,9 +29,12 @@ public class Meteorite extends Entity {
private Rectangle warningRect;
private long warningTime;
private Sprite[] img, warning;
private Sound sound;

public Meteorite(Sprite[] textures, Sprite[] warning) {
public Meteorite(Sprite[] textures, Sprite[] warning, Sound sound) {
super(0, 0);
this.sound = sound;

Random r = new Random();
int direction = r.nextInt(360+1);
health = r.nextInt(2)+3;
Expand Down Expand Up @@ -110,5 +114,6 @@ public void destroy(){
GameScreen.entities.add(new Explosion((int) collision.getXCenter(),
(int) collision.getYCenter()));
GameScreen.entities.remove(this);
sound.play(0.6f);
}
}
9 changes: 9 additions & 0 deletions core/src/ga/gussio/ld38/earthinvaders/entities/Player.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ga.gussio.ld38.earthinvaders.entities;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
Expand All @@ -24,11 +25,17 @@ public class Player extends Entity {

private Sprite img;

private Sound[] shoot;

public Player() {
super(0, 0);
this.x = (float) (GameScreen.earth.getXCenter() + radius*Math.sin(angle));
this.y = (float) (GameScreen.earth.getYCenter() + radius*Math.cos(angle));
img = new Sprite(new Texture(Gdx.files.internal("player.png")));
shoot = new Sound[4];
for(int i = 1; i <= shoot.length; i++){
shoot[i-1] = Gdx.audio.newSound(Gdx.files.internal("sound/shoot"+i+".wav"));
}
}

@Override
Expand Down Expand Up @@ -57,6 +64,8 @@ public void shoot(){
if(shootInterval == maxShootInterval){
GameScreen.entities.add(new Bullet(Game.WIDTH/2, Game.HEIGHT/2, angle));
shootInterval--;
Random r = new Random();
shoot[r.nextInt(3)+1].play(0.6f);
}
}

Expand Down
15 changes: 14 additions & 1 deletion core/src/ga/gussio/ld38/earthinvaders/screen/GameScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ga.gussio.ld38.earthinvaders.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.OrthographicCamera;
Expand Down Expand Up @@ -54,6 +56,9 @@ public class GameScreen extends Screen implements InputListener {
private int scoreTimer = 0;
private boolean appliedScore = false;

private Music soundtrack;
private Sound meteorDestroySound;

public GameScreen() {
entities.clear();
camera = new OrthographicCamera();
Expand Down Expand Up @@ -86,6 +91,11 @@ public GameScreen() {
exit = new Button(1230, 450, "buttons/exit.png");
retry = new Button(500, 450, "buttons/retry.png");

soundtrack = Gdx.audio.newMusic(Gdx.files.internal("sound/soundtrack.wav"));
meteorDestroySound = Gdx.audio.newSound(Gdx.files.internal("sound/explosion.wav"));

soundtrack.setLooping(true);
soundtrack.play();
//generating randomized background
Random r = new Random();
background = new Particle[r.nextInt(55-45)+45];
Expand Down Expand Up @@ -182,7 +192,7 @@ else if (rightButton.clicked)
}

if (System.currentTimeMillis() > spawnTimer) {
entities.add(new Meteorite(meteoriteSprites, warningSprites));
entities.add(new Meteorite(meteoriteSprites, warningSprites, meteorDestroySound));
long dtime = System.currentTimeMillis() - startTime;
if (dtime > 10000) {
startTime = System.currentTimeMillis();
Expand Down Expand Up @@ -224,6 +234,9 @@ public void dispose() {
health = maxHealth;
score = 0;
dmgAnimation = 0;
soundtrack.stop();
soundtrack.dispose();
meteorDestroySound.dispose();
}

public static void damageEarth(int hits){
Expand Down

0 comments on commit 83fd61a

Please sign in to comment.