Merge remote-tracking branch 'origin/master'
commit
ed5f8be65b
|
@ -22,7 +22,9 @@ public class FileManager {
|
||||||
} else {
|
} else {
|
||||||
Scanner fileReader = new Scanner(newFile);
|
Scanner fileReader = new Scanner(newFile);
|
||||||
// using the delimiter \\Z reads the entire file at once
|
// using the delimiter \\Z reads the entire file at once
|
||||||
return fileReader.useDelimiter("\\Z").next();
|
String returnString = fileReader.useDelimiter("\\Z").next();
|
||||||
|
fileReader.close();
|
||||||
|
return returnString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +37,18 @@ public class FileManager {
|
||||||
} else {
|
} else {
|
||||||
objectStream = new ObjectInputStream(fileStream);
|
objectStream = new ObjectInputStream(fileStream);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
o = objectStream.readObject();
|
o = objectStream.readObject();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// please note that the broad exception Exception was used here
|
||||||
|
// as in the event of any exception, the object should still be closed
|
||||||
|
// additionally, the exception is reraised, so no information is lost from being too coarse
|
||||||
|
objectStream.close();
|
||||||
|
fileStream.close();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
objectStream.close();
|
objectStream.close();
|
||||||
fileStream.close();
|
fileStream.close();
|
||||||
System.out.println("done");
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
||||||
try {
|
try {
|
||||||
if (isDialogue || isPaused) {
|
if (isDialogue || isPaused) {
|
||||||
mouseAlreadyTranslated = true;
|
mouseAlreadyTranslated = true;
|
||||||
keyPressed(new KeyEvent(new Component() {}, 0, 0, 0, KeyEvent.VK_ENTER));
|
keyPressed(new KeyEvent(new Component() {}, 0, 0, 0, KeyEvent.VK_ENTER, (char)KeyEvent.VK_ENTER));
|
||||||
} else {
|
} else {
|
||||||
player.mousePressed(e);
|
player.mousePressed(e);
|
||||||
}
|
}
|
||||||
|
@ -519,9 +519,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
||||||
public void updateParticle() throws IOException {
|
public void updateParticle() throws IOException {
|
||||||
if(particles.size()<10) {
|
if(particles.size()<10) {
|
||||||
for (int i = 0; i < particleTiles.size(); i++) {
|
for (int i = 0; i < particleTiles.size(); i++) {
|
||||||
if (GlobalState.randInt(1, 20) == 1) {
|
if (UtilityFunction.randInt(1, 20) == 1) {
|
||||||
particles.add(new Particle(particleTiles.get(i).x + GlobalState.randInt(0, Tile.length), particleTiles.get(i).y + GlobalState.randInt(0, Tile.length / 2),
|
particles.add(new Particle(particleTiles.get(i).x + UtilityFunction.randInt(0, Tile.length), particleTiles.get(i).y + UtilityFunction.randInt(0, Tile.length / 2),
|
||||||
GlobalState.randInt(-3, 3), GlobalState.randInt(-5, 2), GlobalState.randInt(5, 9), "img/particles/LavaParticle.png"));
|
UtilityFunction.randInt(-3, 3), UtilityFunction.randInt(-5, 2), UtilityFunction.randInt(5, 9), "img/particles/LavaParticle.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,4 @@ import java.io.Serializable;
|
||||||
|
|
||||||
public class GlobalState implements Serializable {
|
public class GlobalState implements Serializable {
|
||||||
public static final int second = 10;
|
public static final int second = 10;
|
||||||
public static int randInt(int low, int high){
|
|
||||||
return (int)(Math.random()*(high-low+1))+low;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if (hoverCheck(e)) {
|
if (hoverCheck(e)) {
|
||||||
keyPressed(new KeyEvent(new Component() {
|
keyPressed(new KeyEvent(new Component() {
|
||||||
}, 0, 0, 0, KeyEvent.VK_ENTER));
|
}, 0, 0, 0, KeyEvent.VK_ENTER, (char)KeyEvent.VK_ENTER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,8 +7,6 @@ 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.ImageObserver;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -421,9 +419,9 @@ public class Player extends GenericSprite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void addParticle(int x) throws IOException {
|
public void addParticle(int x) throws IOException {
|
||||||
if(GlobalState.randInt(1,3)==3) {
|
if(UtilityFunction.randInt(1,3)==3) {
|
||||||
GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.camera.x + WIDTH / 2 + GlobalState.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2)
|
GameFrame.game.particles.add(new Particle(this.x + GameFrame.game.camera.x + WIDTH / 2 + UtilityFunction.randInt(-PLAYER_WIDTH / 2, PLAYER_WIDTH / 2)
|
||||||
, (int) (y + HEIGHT * 0.95), GlobalState.randInt(-2, 2) + x, GlobalState.randInt(-4, 1), GlobalState.randInt(1, 7), "img/particles/GrassParticle.png"));
|
, (int) (y + HEIGHT * 0.95), UtilityFunction.randInt(-2, 2) + x, UtilityFunction.randInt(-4, 1), UtilityFunction.randInt(1, 7), "img/particles/GrassParticle.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int draw(Graphics g, int frame) {
|
public int draw(Graphics g, int frame) {
|
||||||
|
|
|
@ -214,7 +214,8 @@ public class StickyBomb extends GenericSprite implements Serializable {
|
||||||
g.drawImage(sprite.image, x - GameFrame.game.camera.x - (spriteLength-length)/2, y - (spriteLength-length)/2, spriteLength, spriteLength, null);
|
g.drawImage(sprite.image, x - GameFrame.game.camera.x - (spriteLength-length)/2, y - (spriteLength-length)/2, spriteLength, spriteLength, null);
|
||||||
//g.drawRect(x-GameFrame.game.camera.x,y,length,length);
|
//g.drawRect(x-GameFrame.game.camera.x,y,length,length);
|
||||||
} else if (explosionPixel < explosionSpriteArray.length - 1) {
|
} else if (explosionPixel < explosionSpriteArray.length - 1) {
|
||||||
g.drawImage(explosionSpriteArray[explosionPixel].image, x - GameFrame.game.camera.x - 10*explosionPixel,
|
// please note that the explosion is completely centered on the x plane ("5*") but tends upwards on the y plane ("10*")
|
||||||
|
g.drawImage(explosionSpriteArray[explosionPixel].image, x - GameFrame.game.camera.x - 5*explosionPixel,
|
||||||
y-10*explosionPixel, spriteLength+10*explosionPixel, spriteLength+10*explosionPixel, null);
|
y-10*explosionPixel, spriteLength+10*explosionPixel, spriteLength+10*explosionPixel, null);
|
||||||
explosionCounter += 1;
|
explosionCounter += 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -29,4 +29,8 @@ public final class UtilityFunction {
|
||||||
}
|
}
|
||||||
return currentBox;
|
return currentBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int randInt(int low, int high){
|
||||||
|
return (int)(Math.random()*(high-low+1))+low;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue