Add stuff

master
John 2022-06-17 13:55:23 -04:00
parent 16d1da6fa1
commit a226a30862
3 changed files with 26 additions and 8 deletions

View File

@ -17,17 +17,17 @@ public class GameFrame extends JFrame{
MenuPanel menu;
public static GamePanel game;
public static CameraPanel main;
SettingPanel settings;
CameraPanel main;
public GameFrame(){
try {
main = new CameraPanel();
main.setLayout(new CardLayout());
menu = new MenuPanel(main);
try {
game = (GamePanel)FileManager.readObjectFromFile("local/game_state.dat", Arrays.asList("Any"));
game.gameFrame = main;
game.isContinue = true;
game.addUserInterface();
game.startThread();
} catch (IOException | ClassNotFoundException | ClassCastException | SecurityException e) {
@ -45,6 +45,7 @@ public class GameFrame extends JFrame{
game.middlewareArray = new ArrayList<Middleware>();
}
*/
menu = new MenuPanel(main);
settings = new SettingPanel(main);
main.add(menu, "menu");
main.add(settings, "settings");

View File

@ -76,6 +76,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
public BufferedImageWrapper narratorPortrait = new BufferedImageWrapper(("img/dialogue/Gunther.png"));
public BufferedImageWrapper villainPortrait = new BufferedImageWrapper(("img/dialogue/Bouncer.png"));
public String lastText;
public boolean isContinue;
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {

View File

@ -29,7 +29,7 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
public Image image;
public Graphics graphics;
public BackgroundImage background;
public TextBox title, enter, settings;
public TextBox title, enter, settings, continueGame;
public ArrayList<TextBox> textBoxArray = new ArrayList<TextBox>();
public Font standardFont = new Font(Font.MONOSPACED, Font.BOLD, 60);
public int playerFrame, enemyFrame;
@ -46,10 +46,14 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
camera = gameFrame.camera;
title = new TextBox(100, 400, 100, GAME_WIDTH, standardFont, "Platformer", null);
enter = new TextBox(300, 600, 100, GAME_WIDTH, standardFont, "Start Game", "game");
settings = new TextBox(400, 600, 100, GAME_WIDTH, standardFont, "Settings", "settings");
continueGame = new TextBox(300, 600, 100, GAME_WIDTH, standardFont, "Continue", "game");
enter = new TextBox(400, 600, 100, GAME_WIDTH, standardFont, "Start Game", "game-start");
settings = new TextBox(500, 600, 100, GAME_WIDTH, standardFont, "Settings", "settings");
textBoxArray.add(enter);
textBoxArray.add(settings);
if (GameFrame.game.isContinue) {
textBoxArray.add(0, continueGame);
}
background = new BackgroundImage(0, 0, backgroundImage, GAME_WIDTH, GAME_HEIGHT, 10, camera);
// the height of 35 is set because it is half of the original tile height (i.e., 70px)
@ -100,6 +104,9 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
public void draw(Graphics g, int playerFrame, int enemyFrame){
background.draw(g);
title.draw(g,null, Color.black);
if (!GameFrame.game.isContinue) {
continueGame.draw(g, null, Color.gray);
}
for (TextBox t: textBoxArray) {
t.draw(g, null, Color.cyan);
}
@ -150,12 +157,21 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
e = UtilityFunction.intercept(e, GameFrame.game.middlewareArray);
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if(textBoxArray.get(currentBox).id.equals("game")){
if(textBoxArray.get(currentBox).id.contains("game")){
gameStart = true;
}
// logic for different screens starts here
CardLayout cardLayout = (CardLayout) gameFrame.getLayout();
cardLayout.show(gameFrame, textBoxArray.get(currentBox).id);
if (textBoxArray.get(currentBox).id.equals("game-start")) {
try {
GameFrame.game = new GamePanel(GameFrame.main); //run GamePanel constructor
} catch (IOException | SpriteException | UnsupportedAudioFileException | LineUnavailableException ex) {
ex.printStackTrace();
}
GameFrame.game.startThread();
((CardLayout)gameFrame.getLayout()).show(gameFrame, "game");
} else {
((CardLayout) gameFrame.getLayout()).show(gameFrame, textBoxArray.get(currentBox).id);
}
} else {
currentBox = UtilityFunction.processBox(e, currentBox, textBoxArray);
}