diff --git a/assets/Map.txt b/assets/Map.txt index ec3ca9d..367d460 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -4,7 +4,7 @@ # ###### # # ##### ###### ###### ###### #### # # ##### ###### ###### #### # -# ##,### # +# ###### # # ##### ###### ,0123, ###### #### # # ### ###### ###### ###### ## # # # # P # # # diff --git a/assets/heart.png b/assets/heart.png new file mode 100644 index 0000000..cca1313 Binary files /dev/null and b/assets/heart.png differ diff --git a/bin/.gitignore b/bin/.gitignore index 0e08c32..cc3ed02 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ /Point.class +/Lives.class diff --git a/bin/Game.class b/bin/Game.class index 49c709f..d7cfcc1 100644 Binary files a/bin/Game.class and b/bin/Game.class differ diff --git a/bin/Player.class b/bin/Player.class index 215dc9b..daa323b 100644 Binary files a/bin/Player.class and b/bin/Player.class differ diff --git a/src/Game.java b/src/Game.java index 251597e..141b813 100644 --- a/src/Game.java +++ b/src/Game.java @@ -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++) { diff --git a/src/Lives.java b/src/Lives.java new file mode 100644 index 0000000..48f99f6 --- /dev/null +++ b/src/Lives.java @@ -0,0 +1,8 @@ + + +public class Lives extends Picture{ + public Lives() { + super("heart"); + } + +} diff --git a/src/Player.java b/src/Player.java index 6395325..113b02e 100644 --- a/src/Player.java +++ b/src/Player.java @@ -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