diff --git a/src/GamePanel.java b/src/GamePanel.java index a26c4c5..c23e04d 100644 --- a/src/GamePanel.java +++ b/src/GamePanel.java @@ -30,6 +30,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ public transient Thread gameThread; public transient Image image; public transient Graphics graphics; + public transient boolean isNewStart = false; public Player player; public BackgroundImage background, cloudOneBackground, cloudTwoBackground, cloudThreeBackground; public int playerFrame, enemyFrame; @@ -113,6 +114,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ // the height of 35 is set because it is half of the original tile height (i.e., 70px) addUserInterface(); this.setPreferredSize(new Dimension(GAME_WIDTH, GAME_HEIGHT)); + isNewStart = true; } public void addUserInterface() { @@ -315,9 +317,11 @@ public class GamePanel extends JPanel implements Runnable, KeyListener, Serializ } //run() method is what makes the game continue running without end. It calls other methods to move objects, check for collision, and update the screen - public void run(){ - LevelManager.setLevel(1); - isDialogue = true; + public void run() { + if (isNewStart) { + LevelManager.setLevel(1); + isDialogue = true; + } //the CPU runs our game code too quickly - we need to slow it down! The following lines of code "force" the computer to get stuck in a loop for short intervals between calling other methods to update the screen. long lastTime = System.nanoTime(); double amountOfTicks = 60; diff --git a/src/Player.java b/src/Player.java index 6860476..15dc504 100644 --- a/src/Player.java +++ b/src/Player.java @@ -225,7 +225,9 @@ public class Player extends GenericSprite { y-=1; isGrounded = false; if(canUpdate(0,-8)) { - jump.start(); + if (jump != null) { + jump.start(); + } } yVelocity = -10; }