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 int score = 0;
|
||||||
|
|
||||||
private JLabel scoreLabel;
|
private JLabel scoreLabel;
|
||||||
|
private JLabel fpsLabel;
|
||||||
private JLabel liveLabels[];
|
private JLabel liveLabels[];
|
||||||
|
|
||||||
private int delaytimer = 4;
|
private int delaytimer = 4;
|
||||||
|
@ -65,7 +65,7 @@ public class Game {
|
||||||
for (int i = 0; i < liveLabels.length; i++) {
|
for (int i = 0; i < liveLabels.length; i++) {
|
||||||
liveLabels[i] = new Lives();
|
liveLabels[i] = new Lives();
|
||||||
panel.add(liveLabels[i]);
|
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));
|
scoreLabel = new JLabel(Integer.toString(score));
|
||||||
|
@ -75,6 +75,13 @@ public class Game {
|
||||||
Font f = new Font("Consolas", Font.BOLD, 24);
|
Font f = new Font("Consolas", Font.BOLD, 24);
|
||||||
scoreLabel.setFont(f);
|
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
|
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
|
frame.addKeyListener(player); // KeyListener wird hinzugefügt, man kann nun Pac-Maan mit der tastatur steuern
|
||||||
|
|
||||||
|
@ -154,22 +161,6 @@ public class Game {
|
||||||
|
|
||||||
while (true) { // Hauptschleife
|
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 (ghosts[0].feared == true) {
|
||||||
if (Ghost.fearedTimer != 0) {
|
if (Ghost.fearedTimer != 0) {
|
||||||
Ghost.fearedTimer--;
|
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++) {
|
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));
|
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
||||||
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18
|
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18
|
||||||
&& 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.right = false;
|
||||||
player.left = 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) {
|
if (frames % 100 == 0) {
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
|
@ -455,10 +462,18 @@ public class Game {
|
||||||
if (empty) {
|
if (empty) {
|
||||||
scoreLabel.setText("YOU WON");
|
scoreLabel.setText("YOU WON");
|
||||||
delay(1000);
|
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
|
// Methode zum verzögern (warten) in ms
|
||||||
|
|
Loading…
Reference in New Issue