master
Chara1236 2022-06-05 12:05:49 -04:00
parent 4d58cece36
commit 76d914955f
1 changed files with 7 additions and 14 deletions

View File

@ -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 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(1200, 100, slimeSpriteArray, 50, 28));
enemy.add(new NonPlayer(0, 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) // 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.setFocusable(true); //make everything in this class appear on the screen
this.addKeyListener(this); //start listening for keyboard input this.addKeyListener(this); //start listening for keyboard input
@ -164,7 +163,6 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
} }
} }
//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 //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(){
try { try {
@ -191,14 +189,9 @@ public class GamePanel extends JPanel implements Runnable, KeyListener{
repaint(); repaint();
if (playerFrameCounter > 5) { if (playerFrameCounter > 5) {
// increment sprite image to be used and keeps it below 12 // increment sprite image to be used and keeps it below 12
playerFrame += 1; playerFrame = (playerFrame + 1) % 11;
playerFrameCounter -= 5; playerFrameCounter -= 5;
} }
if (enemyFrameCounter > 5) {
// increment sprite image to be used and keeps it below 12
enemyFrame += 1;
enemyFrameCounter -= 5;
}
delta--; delta--;
} }
} }