Add stuff
parent
16d1da6fa1
commit
a226a30862
|
@ -17,17 +17,17 @@ public class GameFrame extends JFrame{
|
||||||
|
|
||||||
MenuPanel menu;
|
MenuPanel menu;
|
||||||
public static GamePanel game;
|
public static GamePanel game;
|
||||||
|
public static CameraPanel main;
|
||||||
SettingPanel settings;
|
SettingPanel settings;
|
||||||
CameraPanel main;
|
|
||||||
|
|
||||||
public GameFrame(){
|
public GameFrame(){
|
||||||
try {
|
try {
|
||||||
main = new CameraPanel();
|
main = new CameraPanel();
|
||||||
main.setLayout(new CardLayout());
|
main.setLayout(new CardLayout());
|
||||||
menu = new MenuPanel(main);
|
|
||||||
try {
|
try {
|
||||||
game = (GamePanel)FileManager.readObjectFromFile("local/game_state.dat", Arrays.asList("Any"));
|
game = (GamePanel)FileManager.readObjectFromFile("local/game_state.dat", Arrays.asList("Any"));
|
||||||
game.gameFrame = main;
|
game.gameFrame = main;
|
||||||
|
game.isContinue = true;
|
||||||
game.addUserInterface();
|
game.addUserInterface();
|
||||||
game.startThread();
|
game.startThread();
|
||||||
} catch (IOException | ClassNotFoundException | ClassCastException | SecurityException e) {
|
} catch (IOException | ClassNotFoundException | ClassCastException | SecurityException e) {
|
||||||
|
@ -45,6 +45,7 @@ public class GameFrame extends JFrame{
|
||||||
game.middlewareArray = new ArrayList<Middleware>();
|
game.middlewareArray = new ArrayList<Middleware>();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
menu = new MenuPanel(main);
|
||||||
settings = new SettingPanel(main);
|
settings = new SettingPanel(main);
|
||||||
main.add(menu, "menu");
|
main.add(menu, "menu");
|
||||||
main.add(settings, "settings");
|
main.add(settings, "settings");
|
||||||
|
|
|
@ -76,6 +76,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
||||||
public BufferedImageWrapper narratorPortrait = new BufferedImageWrapper(("img/dialogue/Gunther.png"));
|
public BufferedImageWrapper narratorPortrait = new BufferedImageWrapper(("img/dialogue/Gunther.png"));
|
||||||
public BufferedImageWrapper villainPortrait = new BufferedImageWrapper(("img/dialogue/Bouncer.png"));
|
public BufferedImageWrapper villainPortrait = new BufferedImageWrapper(("img/dialogue/Bouncer.png"));
|
||||||
public String lastText;
|
public String lastText;
|
||||||
|
public boolean isContinue;
|
||||||
|
|
||||||
|
|
||||||
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
||||||
public Image image;
|
public Image image;
|
||||||
public Graphics graphics;
|
public Graphics graphics;
|
||||||
public BackgroundImage background;
|
public BackgroundImage background;
|
||||||
public TextBox title, enter, settings;
|
public TextBox title, enter, settings, continueGame;
|
||||||
public ArrayList<TextBox> textBoxArray = new ArrayList<TextBox>();
|
public ArrayList<TextBox> textBoxArray = new ArrayList<TextBox>();
|
||||||
public Font standardFont = new Font(Font.MONOSPACED, Font.BOLD, 60);
|
public Font standardFont = new Font(Font.MONOSPACED, Font.BOLD, 60);
|
||||||
public int playerFrame, enemyFrame;
|
public int playerFrame, enemyFrame;
|
||||||
|
@ -46,10 +46,14 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
||||||
camera = gameFrame.camera;
|
camera = gameFrame.camera;
|
||||||
|
|
||||||
title = new TextBox(100, 400, 100, GAME_WIDTH, standardFont, "Platformer", null);
|
title = new TextBox(100, 400, 100, GAME_WIDTH, standardFont, "Platformer", null);
|
||||||
enter = new TextBox(300, 600, 100, GAME_WIDTH, standardFont, "Start Game", "game");
|
continueGame = new TextBox(300, 600, 100, GAME_WIDTH, standardFont, "Continue", "game");
|
||||||
settings = new TextBox(400, 600, 100, GAME_WIDTH, standardFont, "Settings", "settings");
|
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(enter);
|
||||||
textBoxArray.add(settings);
|
textBoxArray.add(settings);
|
||||||
|
if (GameFrame.game.isContinue) {
|
||||||
|
textBoxArray.add(0, continueGame);
|
||||||
|
}
|
||||||
|
|
||||||
background = new BackgroundImage(0, 0, backgroundImage, GAME_WIDTH, GAME_HEIGHT, 10, camera);
|
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)
|
// 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){
|
public void draw(Graphics g, int playerFrame, int enemyFrame){
|
||||||
background.draw(g);
|
background.draw(g);
|
||||||
title.draw(g,null, Color.black);
|
title.draw(g,null, Color.black);
|
||||||
|
if (!GameFrame.game.isContinue) {
|
||||||
|
continueGame.draw(g, null, Color.gray);
|
||||||
|
}
|
||||||
for (TextBox t: textBoxArray) {
|
for (TextBox t: textBoxArray) {
|
||||||
t.draw(g, null, Color.cyan);
|
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);
|
e = UtilityFunction.intercept(e, GameFrame.game.middlewareArray);
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||||
if(textBoxArray.get(currentBox).id.equals("game")){
|
if(textBoxArray.get(currentBox).id.contains("game")){
|
||||||
gameStart = true;
|
gameStart = true;
|
||||||
}
|
}
|
||||||
// logic for different screens starts here
|
// logic for different screens starts here
|
||||||
CardLayout cardLayout = (CardLayout) gameFrame.getLayout();
|
if (textBoxArray.get(currentBox).id.equals("game-start")) {
|
||||||
cardLayout.show(gameFrame, textBoxArray.get(currentBox).id);
|
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 {
|
} else {
|
||||||
currentBox = UtilityFunction.processBox(e, currentBox, textBoxArray);
|
currentBox = UtilityFunction.processBox(e, currentBox, textBoxArray);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue