Fixing Jump Bug
parent
2d24fe98fa
commit
bf7d6e4b19
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -104,8 +104,8 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
}
|
||||
if (player.y >= GAME_HEIGHT - Player.PLAYER_HEIGHT) {
|
||||
player.y = GAME_HEIGHT - Player.PLAYER_HEIGHT;
|
||||
if (player.y >= GAME_HEIGHT - Player.BALL_DIAMETER) {
|
||||
player.y = GAME_HEIGHT - Player.BALL_DIAMETER;
|
||||
if (player.y >= GAME_HEIGHT - Player.PLAYER_HEIGHT) {
|
||||
player.y = GAME_HEIGHT - Player.PLAYER_HEIGHT;
|
||||
player.yVelocity = 0;
|
||||
player.isGrounded = true;
|
||||
}
|
||||
|
@ -115,12 +115,12 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
if (player.x <= 0) {
|
||||
player.x = 0;
|
||||
}
|
||||
}
|
||||
if (player.x + Player.PLAYER_WIDTH >= GAME_WIDTH) {
|
||||
player.x = GAME_WIDTH - Player.PLAYER_WIDTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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(){
|
||||
|
@ -142,7 +142,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
checkCollision();
|
||||
repaint();
|
||||
if (frameCounter > 10) {
|
||||
System.out.println(frameCounter);
|
||||
// increment sprite image to be used and keeps it below 12
|
||||
frame = (frame + 1) % 11;
|
||||
frameCounter -= 10;
|
||||
|
|
|
@ -13,8 +13,8 @@ public class GenericSprite extends Rectangle{
|
|||
public double xVelocity;
|
||||
public final double SPEED = 20; //movement speed of ball
|
||||
public final double speedCap = 7; //Speed cap of ball
|
||||
public static final int BALL_DIAMETER = 20; //size of ball
|
||||
|
||||
public static final int WIDTH = 20; //size of ball
|
||||
public static final int HEIGHT = 20; //size of ball
|
||||
public boolean rightPressed = false;
|
||||
public boolean leftPressed = false;
|
||||
public boolean upPressed= false;
|
||||
|
@ -82,8 +82,8 @@ public class GenericSprite extends Rectangle{
|
|||
if(rightPressed==true){
|
||||
xVelocity+=1;
|
||||
}
|
||||
if(leftPressed==true){
|
||||
xVelocity-=1;
|
||||
if(leftPressed==true) {
|
||||
xVelocity -= 1;
|
||||
}
|
||||
if(upPressed&isGrounded){
|
||||
yVelocity = -10;
|
||||
|
@ -106,7 +106,7 @@ public class GenericSprite extends Rectangle{
|
|||
//draws the current location of the ball to the screen
|
||||
public void draw(Graphics g){
|
||||
g.setColor(Color.black);
|
||||
g.fillOval(x, y, BALL_DIAMETER, BALL_DIAMETER);
|
||||
g.fillOval(x, y, WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
}
|
|
@ -9,8 +9,8 @@ import java.awt.image.ImageObserver;
|
|||
|
||||
public class Player extends GenericSprite {
|
||||
public final int SPEED = 5;
|
||||
public static final int PLAYER_WIDTH = 8;
|
||||
public static final int PLAYER_HEIGHT = 80;
|
||||
public static final int PLAYER_WIDTH = 72;
|
||||
public static final int PLAYER_HEIGHT = 97;
|
||||
public int upKey, downKey, rightKey, leftKey;
|
||||
// sA[0] is -x, -y
|
||||
// sA[1] is x, -y
|
||||
|
|
Loading…
Reference in New Issue