Merge remote-tracking branch 'origin/master'
commit
bc7dfd982a
|
@ -1,7 +1,7 @@
|
|||
//The purpose of this class is to create a background which acts as a parallax
|
||||
import javax.swing.*;
|
||||
// Eric Li, Charlie Zhao, ICS4U, Finished 2022-06-15
|
||||
// the purpose of this class is to create a background
|
||||
// this background can also be parallax and move as the player moves
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BackgroundImage implements Serializable {
|
||||
|
@ -23,8 +23,9 @@ public class BackgroundImage implements Serializable {
|
|||
this.camera = camera;
|
||||
}
|
||||
public void draw(Graphics g){
|
||||
// draw image, image moves one pixel every parallaxRatio pixels the camera moves
|
||||
g.drawImage(backgroundImage.image, x-camera.x/parallaxRatio % GamePanel.GAME_WIDTH, y, width, height, null);
|
||||
// added to prevent the background image from disappearing
|
||||
// draws second image so that the background is always present
|
||||
g.drawImage(backgroundImage.image, x-camera.x/parallaxRatio % GamePanel.GAME_WIDTH + GamePanel.GAME_WIDTH - 1, y, width, height, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
// Eric Li, Charlie Zhao, ICS4U, Finished 2022-06-17
|
||||
// this class shows the projected trajectory of a bomb based on the current mouse position
|
||||
|
||||
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;
|
||||
|
||||
|
@ -13,11 +15,14 @@ public class BombDirectionShow extends StickyBomb implements Serializable {
|
|||
}
|
||||
|
||||
public void draw(Graphics g) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||
// updates realX (affected by camera.x)
|
||||
update();
|
||||
isMove = true;
|
||||
// renders a maximum of 10 rectangles
|
||||
int loopCounter = 0;
|
||||
while(isMove&&loopCounter<10) {
|
||||
super.move();
|
||||
// draws rectangles if they don't intersect a tile
|
||||
if(isMove&&canUpdate(0,0)) {
|
||||
g.drawRect(x - GameFrame.game.camera.x, y, 2, 2);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Eric Li, Charlie Zhao, ICS4U, Finished 2022-06-19
|
||||
// Enables serialization of the otherwise unserializable BufferedImage object
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
|
@ -11,28 +14,34 @@ public class BufferedImageWrapper implements Serializable {
|
|||
public String imageString;
|
||||
public Boolean flipImage = false;
|
||||
|
||||
// same constructor as BufferedImage
|
||||
public BufferedImageWrapper(int width, int height, int imageType) {
|
||||
image = new BufferedImage(width, height, imageType);
|
||||
}
|
||||
|
||||
// same constructor as BufferedImage
|
||||
public BufferedImageWrapper(int width, int height, int imageType, IndexColorModel cm) {
|
||||
image = new BufferedImage(width, height, imageType, cm);
|
||||
}
|
||||
|
||||
// same constructor as BufferedImage
|
||||
public BufferedImageWrapper(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?, ?> properties) {
|
||||
image = new BufferedImage(cm, raster, isRasterPremultiplied, properties);
|
||||
}
|
||||
|
||||
// directly load an image into the object
|
||||
public BufferedImageWrapper(BufferedImage image) {
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
// save a file location to load the image from
|
||||
public BufferedImageWrapper(String imageString) throws IOException {
|
||||
image = GamePanel.getImage(imageString);
|
||||
this.imageString = imageString;
|
||||
this(imageString, false);
|
||||
}
|
||||
|
||||
// save a file location to load the image from, and flip the image if necessary
|
||||
public BufferedImageWrapper(String imageString, boolean flip) throws IOException {
|
||||
// flip the image by calling the GamePanel static method if the flip boolean is passed as true
|
||||
BufferedImage temporaryImage = GamePanel.getImage(imageString);
|
||||
if (flip) {
|
||||
image = GamePanel.flipImageHorizontally(temporaryImage);
|
||||
|
@ -43,33 +52,41 @@ public class BufferedImageWrapper implements Serializable {
|
|||
this.imageString = imageString;
|
||||
}
|
||||
|
||||
// empty constructor to allow using the custom serializing method readObject
|
||||
public BufferedImageWrapper() {}
|
||||
|
||||
// custom writeObject method that allows writing an otherwise unserializable method to disk
|
||||
@Serial
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
// save whether the image is flipped
|
||||
out.writeObject(flipImage);
|
||||
// if the imageString is present, write that to disk to prevent excessive disk writes
|
||||
if (imageString != null) {
|
||||
out.writeObject(imageString);
|
||||
} else {
|
||||
} else { // otherwise, write the image to disk
|
||||
ImageIO.write(image, "png", out); // png is lossless
|
||||
}
|
||||
}
|
||||
|
||||
// custom readObject method that allows reading an otherwise unserializable method from disk
|
||||
@Serial
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
Object o;
|
||||
// read whether the image is flipped or not
|
||||
flipImage = (Boolean)in.readObject();
|
||||
o = in.readObject();
|
||||
// if the loaded object is a string, load the image residing at the path received from Path.of(string)
|
||||
if (o instanceof String) {
|
||||
BufferedImage temporaryImage;
|
||||
this.imageString = (String)o;
|
||||
temporaryImage = GamePanel.getImage(imageString);
|
||||
// then flip the image if the flipImage boolean is true
|
||||
if (flipImage) {
|
||||
image = GamePanel.flipImageHorizontally(temporaryImage);
|
||||
} else {
|
||||
image = temporaryImage;
|
||||
}
|
||||
} else {
|
||||
} else { // otherwise, load the image directly from the save file
|
||||
image = ImageIO.read(in);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import java.io.Serializable;
|
||||
|
||||
// Eric Li, Charlie Zhao, ICS4U, Finished 2022-06-12
|
||||
//This class controls the x-scrolling aspect for the player
|
||||
//If you look at the players absolute position(Relative to the screen), the players y position changes, but the x position
|
||||
//never actually changes.
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Camera implements Serializable {
|
||||
public int x;
|
||||
public Camera(int x){
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// Eric Li, Charlie Zhao, ICS4U, Finished 2022-06-19
|
||||
// This class extends JPanel and adds a Camera to it, allowing it to keep the same camera object
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class CameraPanel extends JPanel {
|
||||
// creates new camera
|
||||
public Camera camera = new Camera(0);
|
||||
|
||||
public CameraPanel() {}
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
//This class allows us to input and output flies useful for
|
||||
// inputting levels and making save data.
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
// TODO: close scanner etc after use
|
||||
public final class FileManager {
|
||||
|
||||
// will create file if it doesn't exist
|
||||
|
|
|
@ -28,7 +28,6 @@ public class GameFrame extends JFrame{
|
|||
main = new CameraPanel();
|
||||
main.setLayout(new CardLayout());
|
||||
try {
|
||||
System.out.println("done2");
|
||||
game = (GamePanel)FileManager.readObjectFromFile("local/game_state.dat", Arrays.asList("Any"));
|
||||
game.gameFrame = main;
|
||||
game.isContinue = true;
|
||||
|
|
|
@ -39,6 +39,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
public static Font loreFont = new Font(Font.MONOSPACED, Font.ITALIC + Font.BOLD, 36);
|
||||
public static Color tutorialColor = Color.darkGray;
|
||||
public static Color loreColor = Color.lightGray;
|
||||
public int level = 1;
|
||||
public PauseMenu loadingMenu;
|
||||
|
||||
public int bombCount;
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
import javax.imageio.ImageIO;
|
||||
import javax.sound.sampled.LineUnavailableException;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LevelManager implements Serializable {
|
||||
public static int level = 1;
|
||||
public static int xSpawn = -400;
|
||||
public static int ySpawn = 450;
|
||||
|
||||
|
@ -20,7 +17,7 @@ public class LevelManager implements Serializable {
|
|||
GameFrame.game.fireballs.clear();
|
||||
GameFrame.game.player.yVelocity = 0;
|
||||
GameFrame.game.player.xVelocity = 0;
|
||||
LevelManager.level = level;
|
||||
GameFrame.game.level = level;
|
||||
if(level == 1){
|
||||
//-400/450
|
||||
xSpawn = -400;
|
||||
|
@ -88,7 +85,6 @@ public class LevelManager implements Serializable {
|
|||
setLevel(level, false);
|
||||
}
|
||||
public static void nextLevel(){
|
||||
setLevel(level+1);
|
||||
// System.out.println("done222");
|
||||
setLevel(GameFrame.game.level+1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,13 +292,13 @@ public class Player extends GenericSprite {
|
|||
|
||||
public void reset() throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||
SoundWrapper.playSound("sound/OOF.wav");
|
||||
LevelManager.setLevel(LevelManager.level, true);
|
||||
LevelManager.setLevel(GameFrame.game.level, true);
|
||||
GameFrame.game.camera.x = LevelManager.xSpawn;
|
||||
y = LevelManager.ySpawn;
|
||||
holdingSteel = false;
|
||||
}
|
||||
public void resetNoSound() throws IOException {
|
||||
LevelManager.setLevel(LevelManager.level, true);
|
||||
LevelManager.setLevel(GameFrame.game.level, true);
|
||||
GameFrame.game.camera.x = LevelManager.xSpawn;
|
||||
y = LevelManager.ySpawn;
|
||||
holdingSteel = false;
|
||||
|
|
Loading…
Reference in New Issue