lebensanzeige hinzugefügt

master
Lenz Wiechers 2020-06-06 15:19:33 +02:00
parent 870424d1c5
commit 28f85f09de
8 changed files with 30 additions and 13 deletions

View File

@ -4,7 +4,7 @@
# ###### #
# ##### ###### ###### ###### #### #
# ##### ###### ###### #### #
# ##,### #
# ###### #
# ##### ###### ,0123, ###### #### #
# ### ###### ###### ###### ## #
# # # P # # #

BIN
assets/heart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

1
bin/.gitignore vendored
View File

@ -1 +1,2 @@
/Point.class
/Lives.class

Binary file not shown.

Binary file not shown.

View File

@ -26,7 +26,9 @@ public class Game {
private JLabel scoreLabel;
private int delaytimer = 13;
private JLabel liveLabels[];
private int delaytimer = 12;
@SuppressWarnings("unused")
private long fps = 60;
@ -56,16 +58,18 @@ public class Game {
player = new Player(); // Pac-Man
liveLabels = new JLabel[3];
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);
}
scoreLabel = new JLabel(Integer.toString(score));
panel.add(scoreLabel);
scoreLabel.setForeground(Color.WHITE);
scoreLabel.setBounds(710, -5, 500, 50);
Font f = new Font("Consolas", Font.BOLD, 25);
scoreLabel.setBounds(710, 0, 500, 50);
Font f = new Font("Consolas", Font.BOLD, 24);
scoreLabel.setFont(f);
panel.add(player); // Pac-Man wird dem Panel hinzugefügt
@ -263,11 +267,10 @@ public class Game {
&& player.getPos('x', 0) > Map.points[j][i].xPos - 5
&& player.getPos('y', 0) < Map.points[j][i].yPos + 5
&& player.getPos('y', 0) > Map.points[j][i].yPos - 5) {
Map.points[j][i].setBounds(0, 0, 0, 0);
Map.points[j][i] = null;
score++;
scoreLabel.setText(Integer.toString(score));
@ -286,6 +289,11 @@ public class Game {
&& player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) {
player.lives--;
liveLabels[player.lives].setBounds(0, 0, 0, 0);
if (player.lives == 0) {
System.exit(0);
}
System.out.println(player.lives);
delay(200);
for (int j = 0; j < ghosts.length; j++) {

8
src/Lives.java Normal file
View File

@ -0,0 +1,8 @@
public class Lives extends Picture{
public Lives() {
super("heart");
}
}

View File

@ -15,7 +15,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
public int lives = 3;
private float speed = 0.0000001f; // Diee Geschwindigkeit von Pac-man. In alle Richtungen gleich. Muss so klein
private float speed = 0.00000008f; // Diee Geschwindigkeit von Pac-man. In alle Richtungen gleich. Muss so klein
// sein wegen delta time
public long timer; // Variable die speichert zu welchem Zeitpunkt eine Änderung der Richtung