|
|
|
@ -45,8 +45,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
// keeps track of how many ticks has elapsed since last frame change
|
|
|
|
|
public int playerFrameCounter = 0;
|
|
|
|
|
public int timeSinceLastSave = 0;
|
|
|
|
|
public boolean isPaused, isDialogue, waitForDialogue, mouseAlreadyTranslated;
|
|
|
|
|
public PauseMenu pauseMenu;
|
|
|
|
|
public transient boolean isPaused;
|
|
|
|
|
public boolean isDialogue, waitForDialogue, mouseAlreadyTranslated;
|
|
|
|
|
public PauseMenu pauseMenu, pauseMenuExitOne, pauseMenuExitTwo, pauseMenuResume;
|
|
|
|
|
public DialogueMenu dialogueMenu;
|
|
|
|
|
public ArrayList<String> dialogueArray = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
@ -93,7 +94,10 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
cloudOneBackground = new BackgroundImage(200, 200, cloud1, cloud1.image.getWidth(), cloud1.image.getHeight(), 5, camera);
|
|
|
|
|
cloudTwoBackground = new BackgroundImage(600, 250, cloud2, cloud2.image.getWidth(), cloud3.image.getHeight(), 5, camera);
|
|
|
|
|
cloudThreeBackground = new BackgroundImage(1000, 200, cloud3, cloud2.image.getWidth(), cloud3.image.getHeight(), 5, camera);
|
|
|
|
|
pauseMenu = new PauseMenu(GAME_HEIGHT/2, 100, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 60), "Paused");
|
|
|
|
|
pauseMenu = new PauseMenu(GAME_HEIGHT/2, 100, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 60), "Paused", true);
|
|
|
|
|
pauseMenuExitOne = new PauseMenu(GAME_HEIGHT/2, 0, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 24), "Press ENTER to return", true);
|
|
|
|
|
pauseMenuExitTwo = new PauseMenu(GAME_HEIGHT/2, -20, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 24), "to the main menu", true);
|
|
|
|
|
pauseMenuResume = new PauseMenu(GAME_HEIGHT/2, -50, 400, 400, GAME_WIDTH, new Font(Font.MONOSPACED, Font.BOLD, 18), "(or press ESC to resume)", true);
|
|
|
|
|
dialogueMenu = new DialogueMenu(GAME_HEIGHT-100, 200, new Font(Font.MONOSPACED, Font.BOLD, 20), narratorPortrait, true);
|
|
|
|
|
dialogueArray.add("Did you ever hear the tragedy of Darth Plagueis The Wise?");
|
|
|
|
|
dialogueArray.add("I thought not.");
|
|
|
|
@ -153,16 +157,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
this.setFocusable(true); //make everything in this class appear on the screen
|
|
|
|
|
this.addKeyListener(this); //start listening for keyboard input
|
|
|
|
|
// request focus when the CardLayout selects this game
|
|
|
|
|
this.addComponentListener(new ComponentAdapter() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void componentShown(ComponentEvent cEvt) {
|
|
|
|
|
Component src = (Component) cEvt.getSource();
|
|
|
|
|
src.requestFocusInWindow();
|
|
|
|
|
requestFocusable();
|
|
|
|
|
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
|
|
|
|
addMouseListener();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//add the MousePressed method from the MouseAdapter - by doing this we can listen for mouse input. We do this differently from the KeyListener because MouseAdapter has SEVEN mandatory methods - we only need one of them, and we don't want to make 6 empty methods
|
|
|
|
|
public void addMouseListener() {
|
|
|
|
|
addMouseListener(new MouseAdapter() {
|
|
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
|
try {
|
|
|
|
@ -209,6 +209,18 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void requestFocusable() {
|
|
|
|
|
this.addComponentListener(new ComponentAdapter() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void componentShown(ComponentEvent cEvt) {
|
|
|
|
|
Component src = (Component) cEvt.getSource();
|
|
|
|
|
src.requestFocusInWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// startThread is to be called after the game has started to avoid any issues TODO: better explanation
|
|
|
|
|
public void startThread() {
|
|
|
|
|
//make this class run at the same time as other classes (without this each class would "pause" while another class runs). By using threading we can remove lag, and also allows us to do features like display timers in real time!
|
|
|
|
@ -319,6 +331,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
g.setColor(new Color(255, 255, 255, 100));
|
|
|
|
|
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
|
|
|
|
pauseMenu.draw(g, Color.white, Color.black);
|
|
|
|
|
pauseMenuExitOne.draw(g, new Color(0,0, 0, 0), Color.gray);
|
|
|
|
|
pauseMenuExitTwo.draw(g, new Color(0,0, 0, 0), Color.gray);
|
|
|
|
|
pauseMenuResume.draw(g, new Color(0,0, 0, 0), Color.gray);
|
|
|
|
|
} else if (isDialogue) {
|
|
|
|
|
g.setColor(new Color(255, 255, 255, 100));
|
|
|
|
|
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
|
|
|
@ -513,8 +528,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|
|
|
|
e = UtilityFunction.intercept(e, middlewareArray);
|
|
|
|
|
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
|
|
|
|
isPaused = !isPaused;
|
|
|
|
|
System.out.println(isPaused);
|
|
|
|
|
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
|
|
|
|
if (!waitForDialogue) {
|
|
|
|
|
if (isPaused && (e.getSource() == null)) {
|
|
|
|
|
((CardLayout)gameFrame.getLayout()).show(gameFrame, "menu");
|
|
|
|
|
} else if (!waitForDialogue) {
|
|
|
|
|
waitForDialogue = true;
|
|
|
|
|
} else {
|
|
|
|
|
dialogueMenu.currentFrame = 0;
|
|
|
|
|