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 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

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.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;

View File

@ -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;

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
} 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();

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!
*/
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 {
}

View File

@ -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;

View File

@ -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));

View File

@ -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();
}
}

View File

@ -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;