More sounds

master
Chara1236 2022-06-19 18:10:09 -04:00
parent cf134e3104
commit a7b27828bb
11 changed files with 72 additions and 20 deletions

View File

@ -11,8 +11,8 @@ sssssssssssssssssd llllll
sssssssssssssssssd l qwe qwe sssssssssssssssssd l qwe qwe
sssssssssssssssssd asd asd sssssssssssssssssd asd asd
sssssssssssssssssd bbb 1 zxc zxc sssssssssssssssssd bbb 1 zxc zxc
sssssssssssssssssdbbbbbbbbb sssssssssssssssssdbbbbbbbbbu
sssssssssssssssssd 2 qwwwwwwwwe sssssssssssssssssd 2 qwwwwwwwwe
sssssssssssssssssd qrsssssssstwe sssssssssssssssssd h qrsssssssstwe
sssssssssssssssssd bbb qwwrssssssssssstwe qwe + sssssssssssssssssd bbb k qwwrssssssssssstwe qwe +
ssssssssssssssssstwwwwwwwwwwwwllllllllllllllllllllsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3 ssssssssssssssssstwwwwwwwwwwwwllllllllllllllllllllsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwww3

BIN
sound/OOF.wav Normal file

Binary file not shown.

BIN
sound/explode.wav Normal file

Binary file not shown.

View File

@ -1,5 +1,8 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
public class BombDirectionShow extends StickyBomb implements Serializable { public class BombDirectionShow extends StickyBomb implements Serializable {
@ -9,7 +12,7 @@ public class BombDirectionShow extends StickyBomb implements Serializable {
HEIGHT = 25; HEIGHT = 25;
} }
public void draw(Graphics g){ public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
update(); update();
isMove = true; isMove = true;
int loopCounter = 0; int loopCounter = 0;

View File

@ -1,3 +1,5 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
@ -7,6 +9,8 @@ public class FireBall extends GenericSprite{
public boolean dead; public boolean dead;
private int lifeSpan;
public FireBall(int x, int y, int xv, int yv, String dir,int height, int width) { public FireBall(int x, int y, int xv, int yv, String dir,int height, int width) {
super(x, y, height, width); super(x, y, height, width);
@ -23,6 +27,7 @@ public class FireBall extends GenericSprite{
} }
realX = 0; realX = 0;
dead = false; dead = false;
lifeSpan = 1000;
} }
public void update(){ public void update(){
@ -35,7 +40,11 @@ public class FireBall extends GenericSprite{
} }
return false; return false;
} }
public void move(){ public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
lifeSpan--;
if(lifeSpan<=0){
dead = true;
}
update(); update();
if(canUpdate(xVelocity,yVelocity)) { if(canUpdate(xVelocity,yVelocity)) {
x += xVelocity; x += xVelocity;

View File

@ -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 draw(graphics, playerFrame, enemyFrame);//update the positions of everything on the screen
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(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 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 //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); background.draw(g);
cloudOneBackground.draw(g); cloudOneBackground.draw(g);
cloudTwoBackground.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 //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 //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(); player.move();
for (NonPlayer n: enemy) { for (NonPlayer n: enemy) {
n.move(); n.move();
@ -425,6 +429,10 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
move(); move();
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (UnsupportedAudioFileException e) {
throw new RuntimeException(e);
} catch (LineUnavailableException e) {
throw new RuntimeException(e);
} }
checkCollision(); checkCollision();
updateEnemy(); updateEnemy();

View File

@ -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! 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.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.IOException; 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 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; return false;
} }
public boolean canUpdate(double x, double y){ public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
boolean canUpdate = true; boolean canUpdate = true;
int lowX = Math.max(0, (this.x+GamePanel.GAME_WIDTH/2)/Tile.length-4); int lowX = Math.max(0, (this.x+GamePanel.GAME_WIDTH/2)/Tile.length-4);
int highX = Math.min(lowX + 8, GameFrame.game.map.length); 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 //called frequently from the GamePanel class
//draws the current location of the ball to the screen //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 {
} }

View File

@ -52,7 +52,7 @@ public class NonPlayer extends GenericSprite implements Serializable {
public void update(){ public void update(){
realX = x-GameFrame.game.camera.x; realX = x-GameFrame.game.camera.x;
} }
public void move(){ public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
if (isDead) { if (isDead) {
xVelocity = 0; xVelocity = 0;
// return; // return;

View File

@ -104,7 +104,7 @@ public class Player extends GenericSprite {
} }
// calls parent // calls parent
public boolean canUpdate(double x, double y){ public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
boolean canUpdate = true; boolean canUpdate = true;
int lowX = Math.max(0, ((GameFrame.game.camera.x+GamePanel.GAME_WIDTH)/Tile.length)-4); 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); 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 (collide(GameFrame.game.map[i][j], this.x + x, this.y + y)) {
if (GameFrame.game.map[i][j].isFinish) { if (GameFrame.game.map[i][j].isFinish) {
LevelManager.nextLevel(); LevelManager.nextLevel();
GameFrame.game.player.reset(); GameFrame.game.player.resetNoSound();
return true; return true;
} }
if (GameFrame.game.map[i][j].kills) { 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; // mouseX = MouseInfo.getPointerInfo().getLocation().x;
// mouseY = MouseInfo.getPointerInfo().getLocation().y; // mouseY = MouseInfo.getPointerInfo().getLocation().y;
pickupDelay = Math.max(0,pickupDelay - 1); pickupDelay = Math.max(0,pickupDelay - 1);
@ -281,13 +281,19 @@ public class Player extends GenericSprite {
capSpeed(); 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); LevelManager.setLevel(LevelManager.level, true);
GameFrame.game.camera.x = LevelManager.xSpawn; GameFrame.game.camera.x = LevelManager.xSpawn;
y = LevelManager.ySpawn; y = LevelManager.ySpawn;
holdingSteel = false; holdingSteel = false;
} }
public void mousePressed(MouseEvent e) throws SpriteException, IOException { public void mousePressed(MouseEvent e) throws SpriteException, IOException {
canReach(1,1); canReach(1,1);
mouseX = e.getX(); mouseX = e.getX();
@ -394,7 +400,7 @@ public class Player extends GenericSprite {
mouseY = e.getY(); mouseY = e.getY();
if(e.getButton()==MouseEvent.BUTTON1) { if(e.getButton()==MouseEvent.BUTTON1) {
leftMouseDown = false; leftMouseDown = false;
if (GameFrame.game.bombs.size() < 3 && LevelManager.bombs>0 && !holdingSteel) { if (GameFrame.game.bombs.size() < 2 && LevelManager.bombs>0 && !holdingSteel) {
LevelManager.bombs--; LevelManager.bombs--;
GameFrame.game.bombs.add(new StickyBomb(GameFrame.game.player.x + GameFrame.game.camera.x + WIDTH/2, GameFrame.game.player.y+HEIGHT/2, 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)); (mouseX - GameFrame.game.player.x) / 20, (mouseY - GameFrame.game.player.y) / 10, GameFrame.game.bomb, GameFrame.game.explosionArray));

View File

@ -26,4 +26,15 @@ public class SoundWrapper implements Serializable {
o = in.readObject(); o = in.readObject();
sound = new Sound((String)o); 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();
}
} }

View File

@ -1,7 +1,10 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
public class StickyBomb extends GenericSprite implements 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; 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 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 xDis = GameFrame.game.player.x+Player.PLAYER_WIDTH/2-(realX+(double)length/2);
double hypo = Math.sqrt(yDis*yDis+xDis*xDis); double hypo = Math.sqrt(yDis*yDis+xDis*xDis);
@ -97,7 +110,7 @@ public class StickyBomb extends GenericSprite implements Serializable {
} }
return false; return false;
} }
public void move(){ public void move() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
boolean checked = false; boolean checked = false;
if(yVelocity>50){yVelocity=50;} if(yVelocity>50){yVelocity=50;}
update(); 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) { if (explosionCounter >= 2) {
explosionPixel += 1; explosionPixel += 1;
explosionCounter -= 2; explosionCounter -= 2;