Animationen + Hud fix
parent
c1559fd691
commit
7e1a4a4325
Binary file not shown.
After Width: | Height: | Size: 236 B |
Binary file not shown.
Before Width: | Height: | Size: 227 B |
BIN
assets/brick.png
BIN
assets/brick.png
Binary file not shown.
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 205 B |
BIN
bin/Game.class
BIN
bin/Game.class
Binary file not shown.
|
@ -26,7 +26,7 @@ public class Game {
|
|||
private int score = 0;
|
||||
|
||||
private JLabel scoreLabel;
|
||||
|
||||
private JLabel fpsLabel;
|
||||
private JLabel liveLabels[];
|
||||
|
||||
private int delaytimer = 4;
|
||||
|
@ -65,7 +65,7 @@ public class Game {
|
|||
for (int i = 0; i < liveLabels.length; i++) {
|
||||
liveLabels[i] = new Lives();
|
||||
panel.add(liveLabels[i]);
|
||||
liveLabels[i].setBounds(710, 30 + 20 * i, 20, 20);
|
||||
liveLabels[i].setBounds(710 + 20 * i, 35 , 20, 20);
|
||||
}
|
||||
|
||||
scoreLabel = new JLabel(Integer.toString(score));
|
||||
|
@ -74,7 +74,14 @@ public class Game {
|
|||
scoreLabel.setBounds(710, 0, 500, 50);
|
||||
Font f = new Font("Consolas", Font.BOLD, 24);
|
||||
scoreLabel.setFont(f);
|
||||
|
||||
|
||||
fpsLabel = new JLabel(Integer.toString(score));
|
||||
panel.add(fpsLabel);
|
||||
fpsLabel.setForeground(Color.WHITE);
|
||||
fpsLabel.setBounds(710, 45, 500, 50);
|
||||
|
||||
fpsLabel.setFont(f);
|
||||
|
||||
panel.add(player); // Pac-Man wird dem Panel hinzugefügt
|
||||
frame.addKeyListener(player); // KeyListener wird hinzugefügt, man kann nun Pac-Maan mit der tastatur steuern
|
||||
|
||||
|
@ -153,23 +160,7 @@ public class Game {
|
|||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
while (true) { // Hauptschleife
|
||||
|
||||
|
||||
for (int i = 0; i < ghosts.length; i++) {
|
||||
if (ghosts[i].getIsDead()) {
|
||||
if (ghosts[i].getDeathTimer() != 0) {
|
||||
ghosts[i].setDeathTimer(ghosts[i].getDeathTimer() - 1);
|
||||
|
||||
} else {
|
||||
ghosts[i].setIsDead(false);
|
||||
ghosts[i].setPos('x', Map.ghost_posX[i]);
|
||||
ghosts[i].setPos('y', Map.ghost_posY[i]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frames++;
|
||||
if (ghosts[0].feared == true) {
|
||||
if (Ghost.fearedTimer != 0) {
|
||||
Ghost.fearedTimer--;
|
||||
|
@ -395,9 +386,23 @@ public class Game {
|
|||
}
|
||||
}
|
||||
|
||||
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
||||
|
||||
|
||||
|
||||
// Geister LOOP
|
||||
for (int i = 0; i < ghosts.length; i++) {
|
||||
//
|
||||
if (ghosts[i].getIsDead()) {
|
||||
if (ghosts[i].getDeathTimer() != 0) {
|
||||
ghosts[i].setDeathTimer(ghosts[i].getDeathTimer() - 1);
|
||||
|
||||
} else {
|
||||
ghosts[i].setIsDead(false);
|
||||
ghosts[i].setPos('x', Map.ghost_posX[i]);
|
||||
ghosts[i].setPos('y', Map.ghost_posY[i]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
||||
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18
|
||||
&& player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 18
|
||||
|
@ -430,11 +435,13 @@ public class Game {
|
|||
player.right = false;
|
||||
player.left = false;
|
||||
}
|
||||
|
||||
// Geister LOOP
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
fps = 1000000000 / dt;
|
||||
|
||||
delay(delaytimer); // Ein delay zum Ende der Hauptschleife
|
||||
// Ein delay zum Ende der Hauptschleife
|
||||
|
||||
if (frames % 100 == 0) {
|
||||
boolean empty = true;
|
||||
|
@ -455,10 +462,18 @@ public class Game {
|
|||
if (empty) {
|
||||
scoreLabel.setText("YOU WON");
|
||||
delay(1000);
|
||||
System.exit(0);
|
||||
System.exit(0); // HIER DEN HIGHSCORE IMPLEMENTIEREN
|
||||
}
|
||||
}
|
||||
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
||||
fps = 1000000000 / dt;
|
||||
fpsLabel.setText("fps: " + Integer.toString((int) fps));
|
||||
frames++; // FRAMES WIRD HOCHGESETZT
|
||||
delay(delaytimer);
|
||||
//
|
||||
}
|
||||
// ENDE DER WHILE-SCHLEIFE
|
||||
|
||||
}
|
||||
|
||||
// Methode zum verzögern (warten) in ms
|
||||
|
|
Loading…
Reference in New Issue