Merged
parent
4d58cece36
commit
76d914955f
|
@ -79,7 +79,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
player = new Player(GAME_WIDTH/2, GAME_HEIGHT/2, 'W', 'A', 'S', 'D', playerSpriteArray); //create a player controlled player, set start location to middle of screenk
|
||||
enemy.add(new NonPlayer(1200, 100, slimeSpriteArray, 50, 28));
|
||||
enemy.add(new NonPlayer(0, 100, slimeSpriteArray, 50, 28));
|
||||
player = new Player(GAME_WIDTH/2, GAME_HEIGHT/2, 'W', 'A', 'S', 'D', spriteArray); //create a player controlled player, set start location to middle of screenk
|
||||
// the height of 35 is set because it is half of the original tile height (i.e., 70px)
|
||||
this.setFocusable(true); //make everything in this class appear on the screen
|
||||
this.addKeyListener(this); //start listening for keyboard input
|
||||
|
@ -133,7 +132,7 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
//handles all collision detection and responds accordingly
|
||||
public void checkCollision() {
|
||||
player.isGrounded = false;
|
||||
for (NonPlayer n : enemy) {
|
||||
for (NonPlayer n: enemy) {
|
||||
n.isGrounded = false;
|
||||
}
|
||||
for (Tile i : map) {
|
||||
|
@ -155,15 +154,14 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
player.x = GAME_WIDTH - Player.PLAYER_WIDTH;
|
||||
}
|
||||
|
||||
for (NonPlayer n : enemy) {
|
||||
for (NonPlayer n: enemy) {
|
||||
if (n.y >= GAME_HEIGHT - n.npcHeight) {
|
||||
n.y = GAME_HEIGHT - n.npcHeight;
|
||||
n.yVelocity = 0;
|
||||
n.isGrounded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//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(){
|
||||
|
@ -191,14 +189,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
|
|||
repaint();
|
||||
if (playerFrameCounter > 5) {
|
||||
// increment sprite image to be used and keeps it below 12
|
||||
playerFrame += 1;
|
||||
playerFrame = (playerFrame + 1) % 11;
|
||||
playerFrameCounter -= 5;
|
||||
}
|
||||
if (enemyFrameCounter > 5) {
|
||||
// increment sprite image to be used and keeps it below 12
|
||||
enemyFrame += 1;
|
||||
enemyFrameCounter -= 5;
|
||||
}
|
||||
delta--;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue