Merge remote-tracking branch 'origin/master'

master
John 2022-06-20 18:21:53 -07:00
commit 32a503a59e
8 changed files with 24 additions and 11 deletions

View File

@ -57,7 +57,7 @@ public class BufferedImageWrapper implements Serializable {
// custom writeObject method that allows writing an otherwise unserializable method to disk // custom writeObject method that allows writing an otherwise unserializable method to disk
@Serial @Serial
private void writeObject(ObjectOutputStream out) throws IOException { public void writeObject(ObjectOutputStream out) throws IOException {
// save whether the image is flipped // save whether the image is flipped
out.writeObject(flipImage); out.writeObject(flipImage);
// if the imageString is present, write that to disk to prevent excessive disk writes // if the imageString is present, write that to disk to prevent excessive disk writes
@ -70,7 +70,7 @@ public class BufferedImageWrapper implements Serializable {
// custom readObject method that allows reading an otherwise unserializable method from disk // custom readObject method that allows reading an otherwise unserializable method from disk
@Serial @Serial
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { public void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
Object o; Object o;
// read whether the image is flipped or not // read whether the image is flipped or not
flipImage = (Boolean)in.readObject(); flipImage = (Boolean)in.readObject();

View File

@ -8,11 +8,11 @@ import java.io.IOException;
public class FireBall extends GenericSprite{ public class FireBall extends GenericSprite{
public String spritePath; public String spritePath;
private int realX; public int realX;
public boolean dead; public boolean dead;
private int lifeSpan; public int lifeSpan;
// called every time GamePanel.updateShootingBlock is called // called every time GamePanel.updateShootingBlock is called
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) {

View File

@ -339,7 +339,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
} }
// draw bomb counter (bomb image and amount of bombs remaining) // draw bomb counter (bomb image and amount of bombs remaining)
g.drawImage(bomb.image,20,20,35,35,null); g.drawImage(bomb.image,20,20,35,35,null);
g.drawString("X"+LevelManager.bombs+" Sticky bombs",60,40); g.drawString("X"+LevelManager.bombs,60,40);
if (isPaused) { if (isPaused) {
// cover background with translucent rectangle // cover background with translucent rectangle
g.setColor(new Color(255, 255, 255, 100)); g.setColor(new Color(255, 255, 255, 100));

View File

@ -19,7 +19,7 @@ public class Player extends GenericSprite {
public int lastXDirection, lastYDirection, lastFrame; public int lastXDirection, lastYDirection, lastFrame;
public boolean alive; public boolean alive;
private transient Sound jump = new Sound("sound/jump.wav"); public transient Sound jump = new Sound("sound/jump.wav");
public static int mouseX; public static int mouseX;
public static int mouseY; public static int mouseY;
@ -31,7 +31,7 @@ public class Player extends GenericSprite {
boolean canPlaceSteel; boolean canPlaceSteel;
private int pickupDelay = 5; public int pickupDelay = 5;
// sA[0] is -x, -y // sA[0] is -x, -y
// sA[1] is x, -y // sA[1] is x, -y

View File

@ -1,3 +1,5 @@
// Eric Li, Charlie Zhao, ICS4U, Completed 6/20/2022
// SingleTile class adds sprites to the tile class
import java.awt.*; import java.awt.*;
import java.io.Serializable; import java.io.Serializable;
@ -5,13 +7,16 @@ public class SingleTile extends Tile implements Serializable {
public BufferedImageWrapper tileImage; public BufferedImageWrapper tileImage;
public SingleTile(int x, int y, BufferedImageWrapper tileImage) throws SpriteException { public SingleTile(int x, int y, BufferedImageWrapper tileImage) throws SpriteException {
//Creates tile
super(x, y); super(x, y);
//Sets sprite for the tile
if (tileImage.image.getWidth() != tileImage.image.getHeight()) { if (tileImage.image.getWidth() != tileImage.image.getHeight()) {
throw new SpriteException(); throw new SpriteException();
} }
this.tileImage = tileImage; this.tileImage = tileImage;
} }
//Draws the tile on the screen
public void draw(Graphics g){ public void draw(Graphics g){
g.drawImage(tileImage.image, x-GameFrame.game.camera.x, y, length, length, null); g.drawImage(tileImage.image, x-GameFrame.game.camera.x, y, length, length, null);
} }

View File

@ -21,13 +21,13 @@ public class SoundWrapper implements Serializable {
public SoundWrapper() {} public SoundWrapper() {}
@Serial @Serial
private void writeObject(ObjectOutputStream out) throws IOException { public void writeObject(ObjectOutputStream out) throws IOException {
// write location of .wav file (soundString) // write location of .wav file (soundString)
out.writeObject(soundString); out.writeObject(soundString);
} }
@Serial @Serial
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, UnsupportedAudioFileException, LineUnavailableException { public void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, UnsupportedAudioFileException, LineUnavailableException {
// read .wav file located at soundString // read .wav file located at soundString
Object o; Object o;
o = in.readObject(); o = in.readObject();

View File

@ -45,7 +45,7 @@ public class StickyBomb extends GenericSprite implements Serializable {
//Updates the realX position of the bomb, rather than where it is drawn on the screen. //Updates the realX position of the bomb, which is what is drawn on the screen
public void update(){ public void update(){
realX = x - GameFrame.game.camera.x; realX = x - GameFrame.game.camera.x;
} }
@ -214,12 +214,14 @@ public class StickyBomb extends GenericSprite implements Serializable {
//Draws the bomb
public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException { public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
if (explosionCounter >= 2) { if (explosionCounter >= 2) {
explosionPixel += 1; explosionPixel += 1;
explosionCounter -= 2; explosionCounter -= 2;
} }
//If the bomb is alive, don't animate explosion, else do.
if(alive) { if(alive) {
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);

View File

@ -1,3 +1,5 @@
// Eric Li, Charlie Zhao, ICS4U, Completed 6/20/2022
// Tile class allows the creation of tiles which will serve as the playing field of the platformer
import java.awt.*; import java.awt.*;
import java.io.Serializable; import java.io.Serializable;
@ -27,6 +29,7 @@ public class Tile implements Serializable {
public Tile(int x, int y){ public Tile(int x, int y){
//Sets default state of tile
isFinish = false; isFinish = false;
collision = true; collision = true;
kills = false; kills = false;
@ -39,10 +42,13 @@ public class Tile implements Serializable {
previousBlock = null; previousBlock = null;
shootingDir = "none"; shootingDir = "none";
} }
//Updates the real x position of the bomb, what is drawn on the screen
public void update(){ public void update(){
realX = x-GameFrame.game.camera.x; realX = x-GameFrame.game.camera.x;
} }
//Draws the tile on the screen
public void draw(Graphics g){ public void draw(Graphics g){
g.setColor(Color.black); g.setColor(Color.black);
g.fillRect(x-GameFrame.game.camera.x, y, length, length); g.fillRect(x-GameFrame.game.camera.x, y, length, length);