diff --git a/saves/Level2.txt b/saves/Level2.txt index 370f2f6..386082a 100644 --- a/saves/Level2.txt +++ b/saves/Level2.txt @@ -11,8 +11,8 @@ sssssssssssssssssd llllll sssssssssssssssssd l qwe qwe sssssssssssssssssd asd asd sssssssssssssssssd bbb 1 zxc zxc -sssssssssssssssssdbbbbbbbbb +sssssssssssssssssdbbbbbbbbbu sssssssssssssssssd 2 qwwwwwwwwe -sssssssssssssssssd qrsssssssstwe -sssssssssssssssssd bbb qwwrssssssssssstwe qwe + +sssssssssssssssssd h qrsssssssstwe +sssssssssssssssssd bbb k qwwrssssssssssstwe qwe + ssssssssssssssssstwwwwwwwwwwwwllllllllllllllllllllsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3 \ No newline at end of file diff --git a/sound/OOF.wav b/sound/OOF.wav new file mode 100644 index 0000000..c7f7e8f Binary files /dev/null and b/sound/OOF.wav differ diff --git a/sound/explode.wav b/sound/explode.wav new file mode 100644 index 0000000..7f98b51 Binary files /dev/null and b/sound/explode.wav differ diff --git a/src/BombDirectionShow.java b/src/BombDirectionShow.java index 568de43..83dd2a3 100644 --- a/src/BombDirectionShow.java +++ b/src/BombDirectionShow.java @@ -1,5 +1,8 @@ +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; import java.awt.*; import java.awt.image.BufferedImage; +import java.io.IOException; import java.io.Serializable; public class BombDirectionShow extends StickyBomb implements Serializable { @@ -9,7 +12,7 @@ public class BombDirectionShow extends StickyBomb implements Serializable { HEIGHT = 25; } - public void draw(Graphics g){ + public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException { update(); isMove = true; int loopCounter = 0; diff --git a/src/FireBall.java b/src/FireBall.java index 4ff74f2..a589ff3 100644 --- a/src/FireBall.java +++ b/src/FireBall.java @@ -1,3 +1,5 @@ +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; import java.awt.*; import java.io.IOException; @@ -7,6 +9,8 @@ public class FireBall extends GenericSprite{ public boolean dead; + private int lifeSpan; + public FireBall(int x, int y, int xv, int yv, String dir,int height, int width) { super(x, y, height, width); @@ -23,6 +27,7 @@ public class FireBall extends GenericSprite{ } realX = 0; dead = false; + lifeSpan = 1000; } public void update(){ @@ -35,7 +40,11 @@ public class FireBall extends GenericSprite{ } return false; } - public void move(){ + public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException { + lifeSpan--; + if(lifeSpan<=0){ + dead = true; + } update(); if(canUpdate(xVelocity,yVelocity)) { x += xVelocity; diff --git a/src/GamePanel.java b/src/GamePanel.java index 226221a..9b279a5 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -226,13 +226,17 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ draw(graphics, playerFrame, enemyFrame);//update the positions of everything on the screen } catch (IOException e) { throw new RuntimeException(e); + } catch (UnsupportedAudioFileException e) { + throw new RuntimeException(e); + } catch (LineUnavailableException e) { + throw new RuntimeException(e); } g.drawImage(image, 0, 0, this); //move the image on the screen } //call the draw methods in each class to update positions as things move - public void draw(Graphics g, int playerFrame, int enemyFrame) throws IOException { + public void draw(Graphics g, int playerFrame, int enemyFrame) throws IOException, UnsupportedAudioFileException, LineUnavailableException { background.draw(g); cloudOneBackground.draw(g); cloudTwoBackground.draw(g); @@ -336,7 +340,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ //call the move methods in other classes to update positions //this method is constantly called from run(). By doing this, movements appear fluid and natural. If we take this out the movements appear sluggish and laggy - public void move() throws IOException { + public void move() throws IOException, UnsupportedAudioFileException, LineUnavailableException { player.move(); for (NonPlayer n: enemy) { n.move(); @@ -425,6 +429,10 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ move(); } catch (IOException e) { throw new RuntimeException(e); + } catch (UnsupportedAudioFileException e) { + throw new RuntimeException(e); + } catch (LineUnavailableException e) { + throw new RuntimeException(e); } checkCollision(); updateEnemy(); diff --git a/src/GenericSprite.java b/src/GenericSprite.java index 0c92354..edc7504 100644 --- a/src/GenericSprite.java +++ b/src/GenericSprite.java @@ -4,6 +4,8 @@ child of Rectangle because that makes it easy to draw and check for collision In 2D GUI, basically everything is a rectangle even if it doesn't look like it! */ +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; import java.awt.*; import java.awt.event.*; import java.io.IOException; @@ -57,7 +59,7 @@ public class GenericSprite extends Rectangle implements Serializable { public void mouseReleased(MouseEvent e) throws IOException, SpriteException { } - public void move() throws IOException { + public void move() throws IOException, UnsupportedAudioFileException, LineUnavailableException { } @@ -85,7 +87,7 @@ public class GenericSprite extends Rectangle implements Serializable { return false; } - public boolean canUpdate(double x, double y){ + public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException { boolean canUpdate = true; int lowX = Math.max(0, (this.x+GamePanel.GAME_WIDTH/2)/Tile.length-4); int highX = Math.min(lowX + 8, GameFrame.game.map.length); @@ -109,7 +111,7 @@ public class GenericSprite extends Rectangle implements Serializable { } //called frequently from the GamePanel class //draws the current location of the ball to the screen - public void draw(Graphics g) throws IOException { + public void draw(Graphics g) throws IOException, UnsupportedAudioFileException, LineUnavailableException { } diff --git a/src/NonPlayer.java b/src/NonPlayer.java index 9a06f22..cc73459 100644 --- a/src/NonPlayer.java +++ b/src/NonPlayer.java @@ -52,7 +52,7 @@ public class NonPlayer extends GenericSprite implements Serializable { public void update(){ realX = x-GameFrame.game.camera.x; } - public void move(){ + public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException { if (isDead) { xVelocity = 0; // return; diff --git a/src/Player.java b/src/Player.java index 8d98a20..dab9c4d 100644 --- a/src/Player.java +++ b/src/Player.java @@ -104,7 +104,7 @@ public class Player extends GenericSprite { } // calls parent - public boolean canUpdate(double x, double y){ + public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException { boolean canUpdate = true; int lowX = Math.max(0, ((GameFrame.game.camera.x+GamePanel.GAME_WIDTH)/Tile.length)-4); int highX = Math.min(lowX + 8, GameFrame.game.map.length); @@ -116,7 +116,7 @@ public class Player extends GenericSprite { if (collide(GameFrame.game.map[i][j], this.x + x, this.y + y)) { if (GameFrame.game.map[i][j].isFinish) { LevelManager.nextLevel(); - GameFrame.game.player.reset(); + GameFrame.game.player.resetNoSound(); return true; } if (GameFrame.game.map[i][j].kills) { @@ -183,7 +183,7 @@ public class Player extends GenericSprite { } - public void move() throws IOException { + public void move() throws IOException, UnsupportedAudioFileException, LineUnavailableException { // mouseX = MouseInfo.getPointerInfo().getLocation().x; // mouseY = MouseInfo.getPointerInfo().getLocation().y; pickupDelay = Math.max(0,pickupDelay - 1); @@ -281,13 +281,19 @@ public class Player extends GenericSprite { capSpeed(); } - public void reset(){ + public void reset() throws UnsupportedAudioFileException, LineUnavailableException, IOException { + SoundWrapper.playSound("sound/OOF.wav"); + LevelManager.setLevel(LevelManager.level, true); + GameFrame.game.camera.x = LevelManager.xSpawn; + y = LevelManager.ySpawn; + holdingSteel = false; + } + public void resetNoSound() throws UnsupportedAudioFileException, LineUnavailableException, IOException { LevelManager.setLevel(LevelManager.level, true); GameFrame.game.camera.x = LevelManager.xSpawn; y = LevelManager.ySpawn; holdingSteel = false; } - public void mousePressed(MouseEvent e) throws SpriteException, IOException { canReach(1,1); mouseX = e.getX(); @@ -394,7 +400,7 @@ public class Player extends GenericSprite { mouseY = e.getY(); if(e.getButton()==MouseEvent.BUTTON1) { leftMouseDown = false; - if (GameFrame.game.bombs.size() < 3 && LevelManager.bombs>0 && !holdingSteel) { + if (GameFrame.game.bombs.size() < 2 && LevelManager.bombs>0 && !holdingSteel) { LevelManager.bombs--; GameFrame.game.bombs.add(new StickyBomb(GameFrame.game.player.x + GameFrame.game.camera.x + WIDTH/2, GameFrame.game.player.y+HEIGHT/2, (mouseX - GameFrame.game.player.x) / 20, (mouseY - GameFrame.game.player.y) / 10, GameFrame.game.bomb, GameFrame.game.explosionArray)); diff --git a/src/SoundWrapper.java b/src/SoundWrapper.java index 29992e3..50f428f 100644 --- a/src/SoundWrapper.java +++ b/src/SoundWrapper.java @@ -26,4 +26,15 @@ public class SoundWrapper implements Serializable { o = in.readObject(); sound = new Sound((String)o); } + public static void playSound(String filePath) throws UnsupportedAudioFileException, LineUnavailableException, IOException { + Sound sound = new Sound(filePath); + if (sound == null) { + try { + sound = new Sound(filePath); + } catch (UnsupportedAudioFileException | LineUnavailableException | IOException e) { + throw new RuntimeException(e); + } + } + sound.start(); + } } diff --git a/src/StickyBomb.java b/src/StickyBomb.java index 78e1b5b..a1ac00e 100644 --- a/src/StickyBomb.java +++ b/src/StickyBomb.java @@ -1,7 +1,10 @@ +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import java.io.IOException; import java.io.Serializable; public class StickyBomb extends GenericSprite implements Serializable { @@ -44,7 +47,17 @@ public class StickyBomb extends GenericSprite implements Serializable { realX = x - GameFrame.game.camera.x; } - public void explode(){ + public void explode() throws UnsupportedAudioFileException, LineUnavailableException, IOException { +// Sound explode = new Sound("sound/explode.wav"); +// if (explode == null) { +// try { +// explode = new Sound("sound/explode.wav"); +// } catch (UnsupportedAudioFileException | LineUnavailableException e) { +// throw new RuntimeException(e); +// } +// } + // explode.start(); + SoundWrapper.playSound("sound/explode.wav"); double yDis = GameFrame.game.player.y+Player.PLAYER_HEIGHT/2-(y+(double)length/2); double xDis = GameFrame.game.player.x+Player.PLAYER_WIDTH/2-(realX+(double)length/2); double hypo = Math.sqrt(yDis*yDis+xDis*xDis); @@ -97,7 +110,7 @@ public class StickyBomb extends GenericSprite implements Serializable { } return false; } - public void move(){ + public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException { boolean checked = false; if(yVelocity>50){yVelocity=50;} update(); @@ -192,7 +205,7 @@ public class StickyBomb extends GenericSprite implements Serializable { - public void draw(Graphics g){ + public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException { if (explosionCounter >= 2) { explosionPixel += 1; explosionCounter -= 2;