Fix deprecated keyevent, fix access error, center stickybomb explosion

master
John 2022-06-19 15:49:36 -07:00
parent ab3998c77c
commit ef95740a7b
4 changed files with 14 additions and 5 deletions

View File

@ -35,10 +35,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;
} }

View File

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

View File

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

View File

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