master
John 2022-06-15 22:18:19 -04:00
parent 02ef7f3292
commit 7b7821faed
2 changed files with 10 additions and 4 deletions

View File

@ -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(){
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;

View File

@ -225,8 +225,10 @@ public class Player extends GenericSprite {
y-=1;
isGrounded = false;
if(canUpdate(0,-8)) {
if (jump != null) {
jump.start();
}
}
yVelocity = -10;
}
xVelocity *= 0.93;