diff --git a/Platformer.class b/Platformer.class index 595008f..5af6ede 100644 Binary files a/Platformer.class and b/Platformer.class differ diff --git a/Platformer.java b/Platformer.java index e9f5d36..b8b061e 100644 --- a/Platformer.java +++ b/Platformer.java @@ -5,6 +5,7 @@ import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Random; +import javax.sound.sampled.*; import javax.swing.*; public class Platformer extends JPanel implements KeyListener, ActionListener { @@ -44,6 +45,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { boolean gameStarted; Image heart, emptyHeart, slash, amendmentImg, powerImg, pressRImg, endImg, winImg, titleImg; ArrayList numbers; + Clip jumpSound, shootSound, hitSound, collectSound; public Platformer(int boardWidth, int boardHeight, int tileSize) { // setup game @@ -68,6 +70,10 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { endImg = new ImageIcon("Sprites/end.png").getImage(); pressRImg = new ImageIcon("Sprites/PressR.png").getImage(); winImg = new ImageIcon("Sprites/win.png").getImage(); + jumpSound = loadClip("Sounds/jump.wav"); + shootSound = loadClip("Sounds/shoot.wav"); + hitSound = loadClip("Sounds/hit.wav"); + collectSound = loadClip("Sounds/collect.wav"); gameTimer = new Timer(15, this); player = new Player(-20, 0, tileSize, tileSize); collidables = new ArrayList<>(); @@ -172,11 +178,13 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { boolean jumpKeyDown = (isKeyPressed(KeyEvent.VK_W) || isKeyPressed(KeyEvent.VK_UP)); if (jumpKeyDown && !jumpPressed) { if (player.onGround) { + playClip(jumpSound); player.yVelo = -15; player.onGround = false; jumpPressed = true; player.airJumps = 0; } else if (player.curPower == 1 && player.airJumps < 1) { + playClip(jumpSound); player.yVelo = -15; player.airJumps++; jumpPressed = true; @@ -220,6 +228,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { Amendment am = (Amendment) c; if (player.collidesWith(am)) { player.numAmendments++; + playClip(collectSound); } } } @@ -268,6 +277,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { // shoot // projectiles if (isKeyPressed(KeyEvent.VK_SPACE) && player.shootCooldown == 0) { + playClip(shootSound); int projX = player.facing == 1 ? player.x + player.width : player.x - 10; projectiles.add(new Projectile(projX, player.y, tileSize, 10, currentLevel, player.facing)); player.shootCooldown = Player.SHOOT_COOLDOWN; @@ -291,6 +301,7 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { // enemy hits player if (player.collidesWith(e)) { player.takeDamage(); + playClip(hitSound); } } @@ -557,4 +568,23 @@ public class Platformer extends JPanel implements KeyListener, ActionListener { // dont need @Override public void keyTyped(KeyEvent e) {} + + public Clip loadClip(String path) { + try { + AudioInputStream audio = AudioSystem.getAudioInputStream(new File(path)); + Clip clip = AudioSystem.getClip(); + clip.open(audio); + return clip; + } catch (Exception e) { + System.out.println("Could not load sound: " + path); + return null; + } + } + + public void playClip(Clip clip) { + if (clip != null) { + clip.setFramePosition(0); // rewind to start + clip.start(); + } + } } diff --git a/RunForYourRights.jar b/RunForYourRights.jar index b2fe6e1..47c91d9 100644 Binary files a/RunForYourRights.jar and b/RunForYourRights.jar differ diff --git a/Sounds/collect.wav b/Sounds/collect.wav new file mode 100644 index 0000000..1c29617 Binary files /dev/null and b/Sounds/collect.wav differ diff --git a/Sounds/hit.wav b/Sounds/hit.wav new file mode 100644 index 0000000..a76ae32 Binary files /dev/null and b/Sounds/hit.wav differ diff --git a/Sounds/jump.wav b/Sounds/jump.wav new file mode 100644 index 0000000..8ba729d Binary files /dev/null and b/Sounds/jump.wav differ diff --git a/Sounds/shoot.wav b/Sounds/shoot.wav new file mode 100644 index 0000000..93e83fa Binary files /dev/null and b/Sounds/shoot.wav differ