Fix for new game bug
parent
5080aeb539
commit
c07142bc0d
|
@ -79,6 +79,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
public BufferedImageWrapper villainPortrait = new BufferedImageWrapper(("img/dialogue/Bouncer.png"));
|
||||
public String lastText;
|
||||
public boolean isContinue;
|
||||
public boolean isRunning;
|
||||
|
||||
|
||||
public GamePanel(JPanel gameFrame) throws IOException, SpriteException, UnsupportedAudioFileException, LineUnavailableException {
|
||||
|
@ -141,6 +142,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
addUserInterface();
|
||||
this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT));
|
||||
isNewStart = true;
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public void addUserInterface() {
|
||||
|
@ -377,7 +379,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
double delta = 0;
|
||||
long now;
|
||||
|
||||
while(true){ //this is the infinite game loop
|
||||
while(isRunning){ //this is the infinite game loop
|
||||
now = System.nanoTime();
|
||||
delta = delta + (now-lastTime)/ns;
|
||||
lastTime = now;
|
||||
|
@ -421,6 +423,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ
|
|||
delta--;
|
||||
}
|
||||
}
|
||||
System.out.println(Thread.currentThread());
|
||||
}
|
||||
|
||||
public void updateEnemy(){
|
||||
|
|
|
@ -163,11 +163,14 @@ public class MenuPanel extends JPanel implements Runnable, KeyListener{
|
|||
// logic for different screens starts here
|
||||
if (textBoxArray.get(currentBox).id.equals("game-start")) {
|
||||
try {
|
||||
GameFrame.main.remove(GameFrame.game);
|
||||
GameFrame.game.isRunning = false;
|
||||
GameFrame.game = new GamePanel(GameFrame.main); //run GamePanel constructor
|
||||
GameFrame.game.startThread();
|
||||
GameFrame.main.add(GameFrame.game, "game", 0);
|
||||
} 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);
|
||||
|
|
Loading…
Reference in New Issue