Merge remote-tracking branch 'origin/master'

master
John 2022-06-19 17:31:20 -07:00
commit 2e3b2eb90b
7 changed files with 65 additions and 28 deletions

View File

@ -1,18 +1,18 @@
wwwwwwwwwwwwwwwwwe wwwwwwwwwwwwwwwwwe qwwwwwwwwwwwwwwwwe +wwwwwwwwwwwwwwe
sssssssssssssssssd sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd 1 sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd 1 1lllllllll1 1 1 sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd 1 sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
sssssssssssssssssd sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
qe qe sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
u qwe ad ! ad qre sssssssssssssssssd assssssssssssssssd +ssssssssssssssd
h k a d qwe qwe atwwwrd qwwwwwwellllqwwwwwwwe ad sssssssssssssssssd asssssssssssssssstwwwwwwwwwwwe +ssssssssssssssd
sssssssssssssssssd m zxc asd asd zxxxxxc zxxxxxxxllllxxxxxxxxc ad sssssssssssssssssd zxxxxxxxxxxxxxxxxxxxxxxxxxxxftwwwwwwe qe +ssssssssssssssd
sssssssssssssssssd 1 zxc zxc vvvvvvvvwwwwvvvvvvvvv ad sssssssssssssssssd bb zxxxxxxxcooad h +ssssssssssssssd
sssssssssssssssssd qe vvvvvvvvvvvvvvvvvvvvv ad sssssssssssssssssd qe q e bb ad +ssssssssssssssd
sssssssssssssssssdlllllad 2 qwwwwwwwwe vvvvvvvvvvvvvvvvvvvvv ad sssssssssssssssssd ad qwwwrlllte bb ad +ssssssssssssssd
sssssssssssssssssdlllllad bbb s qrsssslssstwe vvvvvvvvvvvvvvvvvvvvv ad sssssssssssssssssd ad asssssssste bb ad +ssssssssssssssd
sssssssssssssssssdllllladbb s ooqwwrssssllssssstwe ! b h !!! qwek vvvvvvvvvvvvvvvvvvvvv + ad sssssssssssssssssd ad ! qwrssssssssstwwwe bb ad h +ssssssssssssssd
ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrsssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww3 ssssssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwrtwwwwwwwwwwwwwwwwrsssssssssssssstwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwd

BIN
sound/grass.wav Normal file

Binary file not shown.

View File

@ -369,7 +369,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
// throw new RuntimeException(e); // throw new RuntimeException(e);
} }
} }
g.drawString(player.xVelocity+"",400,400);
} }
//call the move methods in other classes to update positions //call the move methods in other classes to update positions
@ -443,6 +442,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
} else { } else {
LevelManager.bombs = bombCount; LevelManager.bombs = bombCount;
} }
try {
player.resetNoSound();
} catch (IOException e) {
throw new RuntimeException(e);
}
//the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen. //the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen.
long lastTime = System.nanoTime(); long lastTime = System.nanoTime();
double amountOfTicks = 60; double amountOfTicks = 60;
@ -470,7 +474,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
} }
checkCollision(); checkCollision();
updateEnemy(); updateEnemy();
if(fireballCounter<0){fireballCounter = 100;} if(fireballCounter<0){fireballCounter = 200;}
fireballCounter--; fireballCounter--;
if(fireballCounter == 0){ if(fireballCounter == 0){
updateShootingBlock(); updateShootingBlock();
@ -560,7 +564,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
waitForDialogue = false; waitForDialogue = false;
} }
} else { } else {
player.keyPressed(e); try {
player.keyPressed(e);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} }
} }

View File

@ -40,7 +40,7 @@ public class GenericSprite extends Rectangle implements Serializable {
//called from GamePanel when any keyboard input is detected //called from GamePanel when any keyboard input is detected
//updates the direction of the ball based on user input //updates the direction of the ball based on user input
//if the keyboard input isn't any of the options (d, a, w, s), then nothing happens //if the keyboard input isn't any of the options (d, a, w, s), then nothing happens
public void keyPressed(KeyEvent e){ public void keyPressed(KeyEvent e) throws IOException {
} }

View File

@ -9,8 +9,8 @@ import java.util.Arrays;
public class LevelManager implements Serializable { public class LevelManager implements Serializable {
public static int level = 1; public static int level = 1;
public static int xSpawn = 0; public static int xSpawn = -400;
public static int ySpawn = 600; public static int ySpawn = 500;
public static String filePath; public static String filePath;
@ -22,8 +22,9 @@ public class LevelManager implements Serializable {
GameFrame.game.player.xVelocity = 0; GameFrame.game.player.xVelocity = 0;
LevelManager.level = level; LevelManager.level = level;
if(level == 1){ if(level == 1){
xSpawn = 0; //-400/500
ySpawn = 300; xSpawn = -400;
ySpawn = 500;
filePath = "saves/Level1.txt"; filePath = "saves/Level1.txt";
bombs = 99999; bombs = 99999;
} else if(level == 2){ } else if(level == 2){

View File

@ -59,7 +59,7 @@ public class Player extends GenericSprite {
// moves paddle when key is pressed // moves paddle when key is pressed
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) throws IOException {
if(e.getKeyCode() == KeyEvent.VK_D){ if(e.getKeyCode() == KeyEvent.VK_D){
rightPressed = true; rightPressed = true;
} }
@ -72,6 +72,9 @@ public class Player extends GenericSprite {
if(e.getKeyCode() == KeyEvent.VK_S){ if(e.getKeyCode() == KeyEvent.VK_S){
downPressed = true; downPressed = true;
} }
if(e.getKeyCode() == KeyEvent.VK_R){
resetNoSound();
}
} }
// stops moving paddle when key is released // stops moving paddle when key is released
@ -103,6 +106,9 @@ public class Player extends GenericSprite {
// calls parent // calls parent
public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException { public boolean canUpdate(double x, double y) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
if(this.y+y<=-HEIGHT){
return false;
}
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);
@ -127,6 +133,7 @@ public class Player extends GenericSprite {
} }
} }
} }
return canUpdate; return canUpdate;
} }
@ -184,6 +191,7 @@ public class Player extends GenericSprite {
public void move() throws IOException, UnsupportedAudioFileException, LineUnavailableException { 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);
int Tilex = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length; int Tilex = (mouseX + GameFrame.game.camera.x + GamePanel.GAME_WIDTH / 2) / Tile.length;
int Tiley = (mouseY / Tile.length); int Tiley = (mouseY / Tile.length);
@ -277,6 +285,7 @@ public class Player extends GenericSprite {
reset(); reset();
} }
capSpeed(); capSpeed();
} }
public void reset() throws UnsupportedAudioFileException, LineUnavailableException, IOException { public void reset() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
@ -286,7 +295,7 @@ public class Player extends GenericSprite {
y = LevelManager.ySpawn; y = LevelManager.ySpawn;
holdingSteel = false; holdingSteel = false;
} }
public void resetNoSound() throws UnsupportedAudioFileException, LineUnavailableException, IOException { public void resetNoSound() throws 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;

View File

@ -1,11 +1,29 @@
import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException; import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.*; import java.io.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.*;
public class SoundWrapper implements Serializable { public class SoundWrapper implements Serializable {
transient public Sound sound; transient public Sound sound;
public String soundString; public String soundString;
public static Sound grass;
static {
try {
grass = new Sound("sound/grass.wav");
} catch (UnsupportedAudioFileException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (LineUnavailableException e) {
throw new RuntimeException(e);
}
}
// please note that not as many constructors were implemented as BufferedImage, as this class was created before most sounds were added; // please note that not as many constructors were implemented as BufferedImage, as this class was created before most sounds were added;
// as such, backwards compatibility was not needed // as such, backwards compatibility was not needed
public SoundWrapper(String soundLocation) throws UnsupportedAudioFileException, LineUnavailableException, IOException { public SoundWrapper(String soundLocation) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
@ -37,4 +55,5 @@ public class SoundWrapper implements Serializable {
} }
sound.start(); sound.start();
} }
} }