diff --git a/assets/Blinky.png b/assets/Blinky.png deleted file mode 100644 index e9668b1..0000000 Binary files a/assets/Blinky.png and /dev/null differ diff --git a/assets/Clyde.png b/assets/Clyde.png deleted file mode 100644 index 4974ec3..0000000 Binary files a/assets/Clyde.png and /dev/null differ diff --git a/assets/Geister/Blinky.png b/assets/Geister/Blinky.png new file mode 100644 index 0000000..6f70670 Binary files /dev/null and b/assets/Geister/Blinky.png differ diff --git a/assets/Geister/Clyde.png b/assets/Geister/Clyde.png new file mode 100644 index 0000000..dc9155a Binary files /dev/null and b/assets/Geister/Clyde.png differ diff --git a/assets/Geister/Inky.png b/assets/Geister/Inky.png new file mode 100644 index 0000000..1926aa3 Binary files /dev/null and b/assets/Geister/Inky.png differ diff --git a/assets/Geister/Pinky.png b/assets/Geister/Pinky.png new file mode 100644 index 0000000..331a224 Binary files /dev/null and b/assets/Geister/Pinky.png differ diff --git a/assets/Geister/feared.png b/assets/Geister/feared.png new file mode 100644 index 0000000..6777379 Binary files /dev/null and b/assets/Geister/feared.png differ diff --git a/assets/Inky.png b/assets/Inky.png deleted file mode 100644 index 9383ed5..0000000 Binary files a/assets/Inky.png and /dev/null differ diff --git a/assets/Maps/TestMap.txt b/assets/Maps/TestMap.txt new file mode 100644 index 0000000..a5551bf --- /dev/null +++ b/assets/Maps/TestMap.txt @@ -0,0 +1,19 @@ +######### +#L0123,,# +######### +######### +############## +#,,,,,. # +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,P,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,# +#,,,,,,,,,,,,R +############## \ No newline at end of file diff --git a/assets/Pacman_Down.png b/assets/Pac-Man/Pacman_Down.png similarity index 100% rename from assets/Pacman_Down.png rename to assets/Pac-Man/Pacman_Down.png diff --git a/assets/Pacman_Down1.png b/assets/Pac-Man/Pacman_Down1.png similarity index 100% rename from assets/Pacman_Down1.png rename to assets/Pac-Man/Pacman_Down1.png diff --git a/assets/Pacman_Down3.png b/assets/Pac-Man/Pacman_Down3.png similarity index 100% rename from assets/Pacman_Down3.png rename to assets/Pac-Man/Pacman_Down3.png diff --git a/assets/Pacman_Left.png b/assets/Pac-Man/Pacman_Left.png similarity index 100% rename from assets/Pacman_Left.png rename to assets/Pac-Man/Pacman_Left.png diff --git a/assets/Pacman_Left1.png b/assets/Pac-Man/Pacman_Left1.png similarity index 100% rename from assets/Pacman_Left1.png rename to assets/Pac-Man/Pacman_Left1.png diff --git a/assets/Pacman_Left3.png b/assets/Pac-Man/Pacman_Left3.png similarity index 100% rename from assets/Pacman_Left3.png rename to assets/Pac-Man/Pacman_Left3.png diff --git a/assets/Pacman_Right.png b/assets/Pac-Man/Pacman_Right.png similarity index 100% rename from assets/Pacman_Right.png rename to assets/Pac-Man/Pacman_Right.png diff --git a/assets/Pacman_Right1.png b/assets/Pac-Man/Pacman_Right1.png similarity index 100% rename from assets/Pacman_Right1.png rename to assets/Pac-Man/Pacman_Right1.png diff --git a/assets/Pacman_Right3.png b/assets/Pac-Man/Pacman_Right3.png similarity index 100% rename from assets/Pacman_Right3.png rename to assets/Pac-Man/Pacman_Right3.png diff --git a/assets/Pacman_Up.png b/assets/Pac-Man/Pacman_Up.png similarity index 100% rename from assets/Pacman_Up.png rename to assets/Pac-Man/Pacman_Up.png diff --git a/assets/Pacman_Up1.png b/assets/Pac-Man/Pacman_Up1.png similarity index 100% rename from assets/Pacman_Up1.png rename to assets/Pac-Man/Pacman_Up1.png diff --git a/assets/Pacman_Up3.png b/assets/Pac-Man/Pacman_Up3.png similarity index 100% rename from assets/Pacman_Up3.png rename to assets/Pac-Man/Pacman_Up3.png diff --git a/assets/Pinky.png b/assets/Pinky.png deleted file mode 100644 index b3102c6..0000000 Binary files a/assets/Pinky.png and /dev/null differ diff --git a/assets/cursed.png b/assets/cursed.png deleted file mode 100644 index ff652c5..0000000 Binary files a/assets/cursed.png and /dev/null differ diff --git a/assets/feared.png b/assets/feared.png deleted file mode 100644 index 8f710d3..0000000 Binary files a/assets/feared.png and /dev/null differ diff --git a/bin/Game.class b/bin/Game.class index effacc3..e00d096 100644 Binary files a/bin/Game.class and b/bin/Game.class differ diff --git a/bin/Ghost.class b/bin/Ghost.class index 376c1e8..697b081 100644 Binary files a/bin/Ghost.class and b/bin/Ghost.class differ diff --git a/bin/Main.class b/bin/Main.class index 084339f..03e66e9 100644 Binary files a/bin/Main.class and b/bin/Main.class differ diff --git a/bin/Map.class b/bin/Map.class index 386fbdb..47423ff 100644 Binary files a/bin/Map.class and b/bin/Map.class differ diff --git a/bin/MapMenu.class b/bin/MapMenu.class index 1d6814f..b1f4684 100644 Binary files a/bin/MapMenu.class and b/bin/MapMenu.class differ diff --git a/bin/Player.class b/bin/Player.class index c8abab7..cdeb01b 100644 Binary files a/bin/Player.class and b/bin/Player.class differ diff --git a/src/Game.java b/src/Game.java index 89746be..949764e 100644 --- a/src/Game.java +++ b/src/Game.java @@ -29,7 +29,7 @@ public class Game { private JLabel fpsLabel; private JLabel liveLabels[]; - private int delaytimer = 4; + private long delaytimer = 4000; @SuppressWarnings("unused") private long fps = 60; @@ -46,6 +46,8 @@ public class Game { int minn; int[] HCost = new int[4]; + boolean empty; // Für die Überprüfung, ob alle points weg sind, benötigt + public Game(String selectedMap) { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse // aufgerufen wird?) @@ -65,7 +67,7 @@ public class Game { for (int i = 0; i < liveLabels.length; i++) { liveLabels[i] = new Lives(); panel.add(liveLabels[i]); - liveLabels[i].setBounds(710 + 20 * i, 35 , 20, 20); + liveLabels[i].setBounds(710 + 20 * i, 35, 20, 20); } scoreLabel = new JLabel(Integer.toString(score)); @@ -74,14 +76,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); - + + fpsLabel.setFont(new Font("Consolas", Font.BOLD, 15)); + 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 @@ -112,31 +114,22 @@ public class Game { player.setBounds(player.getPos('x', 0), player.getPos('y', 0), 20, 20); // Pac-Man wird das erste Mal gerendert - for (int i = 0; i < 35; i++) { // für jeden Brick - for (int j = 0; j < 35; j++) { // für jeden Brick + for (int i = 0; i < 35; i++) { // für die ganze Map + for (int j = 0; j < 35; j++) { // für die ganze Map if (Map.bricks[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks panel.add(Map.bricks[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt - Map.bricks[j][i].setBounds(Map.bricks[j][i].xPos, Map.bricks[j][i].yPos, 20, 20); // Rendern des - + // Rendern des Bricks: + Map.bricks[j][i].setBounds(Map.bricks[j][i].xPos, Map.bricks[j][i].yPos, 20, 20); } - } - } - for (int i = 0; i < 35; i++) { // für jeden Brick // points - for (int j = 0; j < 35; j++) { // für jeden Brick - if (Map.points[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks - panel.add(Map.points[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt - Map.points[j][i].setBounds(Map.points[j][i].xPos, Map.points[j][i].yPos, 20, 20); // Rendern des + // Analog für die points und die BigPoints: + if (Map.bigpoints[j][i] != null) { + panel.add(Map.bigpoints[j][i]); + Map.bigpoints[j][i].setBounds(Map.bigpoints[j][i].xPos, Map.bigpoints[j][i].yPos, 20, 20); } - } - } - for (int i = 0; i < 35; i++) { // für jeden Brick // points - for (int j = 0; j < 35; j++) { // für jeden Brick - if (Map.bigpoints[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks - panel.add(Map.bigpoints[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt - Map.bigpoints[j][i].setBounds(Map.bigpoints[j][i].xPos, Map.bigpoints[j][i].yPos, 20, 20); // Rendern - // des - + if (Map.points[j][i] != null) { + panel.add(Map.points[j][i]); + Map.points[j][i].setBounds(Map.points[j][i].xPos, Map.points[j][i].yPos, 20, 20); } } } @@ -152,19 +145,16 @@ public class Game { delay(1000); frame.setVisible(true); - // ----------------------------------------------------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------------------------------------------------------------------------------------------------- - // ----------------------------------------------------------------------------------------------------------------------------------------------------- + while (true) { // Main-Loop - while (true) { // Hauptschleife + dt = System.nanoTime() - lastT; // delta time + lastT = System.nanoTime(); // delta time + + player.setLocation(player.getPos('x', dt), player.getPos('y', dt)); if (ghosts[0].feared == true) { if (Ghost.fearedTimer != 0) { Ghost.fearedTimer--; - } else { for (int i = 0; i < ghosts.length; i++) { ghosts[i].feared = false; @@ -173,10 +163,6 @@ public class Game { } } } - dt = System.nanoTime() - lastT; // delta time - lastT = System.nanoTime(); // delta time - - player.setLocation(player.getPos('x', dt), player.getPos('y', dt)); for (int i = 0; i < ghosts.length; i++) { if (!ghosts[i].getIsDead()) { @@ -341,7 +327,7 @@ public class Game { for (i = 0; i < 4; i++) { ghosts[i].feared = true; Ghost.fearedTimer = 1000; - ghosts[i].changeSauce("feared"); + ghosts[i].changeSauce("Geister/feared"); if (ghosts[i].left) { ghosts[i].dire = 0; } else if (ghosts[i].right) { @@ -363,38 +349,32 @@ public class Game { } } - if (Map.Left != null) { + // Kollision von Pac-Man mit den Portalen: + if (Map.Left != null && Map.Right != null) { if (player.getPos('x', 0) < Map.Left.xPos + 20 && player.getPos('x', 0) > Map.Left.xPos - 20 - && player.getPos('y', 0) < Map.Left.yPos + 20 && player.getPos('y', 0) > Map.Left.yPos - 20) { + && player.getPos('y', 0) < Map.Left.yPos + 20 && player.getPos('y', 0) > Map.Left.yPos - 20 + && Map.Right != null) { + player.xPos = Map.Right.xPos - 20; + player.yPos = Map.Right.yPos; - if (Map.Right != null) { - player.xPos = Map.Right.xPos - 20; - player.yPos = Map.Right.yPos; + } else if (player.getPos('x', 0) < Map.Right.xPos + 20 && player.getPos('x', 0) > Map.Right.xPos - 20 + && player.getPos('y', 0) < Map.Right.yPos + 20 && player.getPos('y', 0) > Map.Right.yPos - 20 + && Map.Left != null) { + player.xPos = Map.Left.xPos + 20; + player.yPos = Map.Left.yPos; - } - } - } - if (Map.Right != null) { - if (player.getPos('x', 0) < Map.Right.xPos + 20 && player.getPos('x', 0) > Map.Right.xPos - 20 - && player.getPos('y', 0) < Map.Right.yPos + 20 && player.getPos('y', 0) > Map.Right.yPos - 20) { - - if (Map.Left != null) { - player.xPos = Map.Left.xPos + 20; - player.yPos = Map.Left.yPos; - - } } } - - // Geister LOOP for (int i = 0; i < ghosts.length; i++) { - // + + ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); // Setzen der Positionen + // der Geister + 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]); @@ -403,31 +383,38 @@ public class Game { } } - ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); + // Kollision der Geister mit Pac-Man: if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18 && player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 18 && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 14 && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 14) - if (ghosts[0].feared) { + if (ghosts[i].feared) { ghosts[i].setIsDead(true); - ghosts[i].setDeathTimer(1000); + ghosts[i].setDeathTimer(1500); ghosts[i].setPos('x', -100); ghosts[i].setPos('y', -100); score += 1000; + scoreLabel.setText(Integer.toString(score)); } else { + player.lives--; - liveLabels[player.lives].setBounds(0, 0, 0, 0); - if (player.lives == 0) { - System.exit(0); + liveLabels[player.lives].setBounds(0, 0, 0, 0); // Das herz wird "entfernt" + + if (player.lives == 0) { // Wenn der Spieler keine Leben mehr übrig hat + System.exit(0); // Das Programm wird beendet } - delay(200); + delay(200); // Damit nicht sofort wieder alle losgeht + + // Die Positionen der Geister werden zurückgesetzt for (int j = 0; j < ghosts.length; j++) { ghosts[j].setPos('x', Map.ghost_posX[j]); ghosts[j].setPos('y', Map.ghost_posY[j]); } + + // Die Position von Pac-Man wird zurückgesetzt, und er bewegt sich nicht mehr. player.setPos('x', Map.pac_posX); player.setPos('y', Map.pac_posY); player.up = false; @@ -436,15 +423,10 @@ public class Game { player.left = false; } - // Geister LOOP - } - // - + } // Ende vom Geister Loop - // Ein delay zum Ende der Hauptschleife - - if (frames % 100 == 0) { - boolean empty = true; + if (frames % 100 == 0) { // Das folgende soll nur alle 100 frames überprüft werden: + empty = true; for (int i = 0; i < 35; i++) { for (int j = 0; j < 35; j++) { if (Map.points[j][i] != null) { @@ -460,27 +442,39 @@ public class Game { } } if (empty) { - scoreLabel.setText("YOU WON"); - delay(1000); - System.exit(0); // HIER DEN HIGHSCORE IMPLEMENTIEREN + fpsLabel.setText("YOU WON"); + delay(5000); + System.exit(0); // Das Programm wird beendet + // 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)); + + fpsLabel.setText("fps: " + Integer.toString((int) fps)); // Refreshen vom fpsLabel frames++; // FRAMES WIRD HOCHGESETZT - delay(delaytimer); - // + + if (frames % 15 == 0) { + fps = 1000000000 / dt; // Berechnen der fps + if (frames > 100) { + if (fps > 200) { + delaytimer += 100; + } else if (fps < 180) { + delaytimer -= 100; + } + } + } + delay(delaytimer); // delay ist wichtig, um die geschwindigkeit der objekte und die fps zu + // kontrollieren } - // ENDE DER WHILE-SCHLEIFE + // ENDE DES MAIN-LOOPS } // Methode zum verzögern (warten) in ms - public void delay(int time) { + public void delay(long time) { try { - Thread.sleep(time); + Thread.sleep(0, (int) time); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/Ghost.java b/src/Ghost.java index 1aa7fdf..bafb9c1 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -24,7 +24,7 @@ public class Ghost extends Picture { // Die public Ghost(int type) { - super("Pinky"); // Aufrufen der übergeordneten Klasse + super("Geister/Pinky"); // Aufrufen der übergeordneten Klasse this.type = type; // xPos = 150 + 40 * index; @@ -33,13 +33,13 @@ public class Ghost extends Picture { // Die public void ogSauce() { if (type == 0) { - this.changeSauce("Blinky"); + this.changeSauce("Geister/Blinky"); } else if (type == 2) { - this.changeSauce("Inky"); + this.changeSauce("Geister/Inky"); } else if (type == 3) { - this.changeSauce("Clyde"); + this.changeSauce("Geister/Clyde"); } else if (type == 1) { - this.changeSauce("Pinky"); + this.changeSauce("Geister/Pinky"); } } diff --git a/src/Player.java b/src/Player.java index 5eaf338..e96eae9 100644 --- a/src/Player.java +++ b/src/Player.java @@ -41,7 +41,7 @@ public class Player extends Picture implements KeyListener { // extends Picture public Player() { // Erstellen des Konstruktors - super("Pacman_Right"); // Aufrufen der übergeordneten Klasse (Picture) + super("Pac-Man/Pacman_Right"); // Aufrufen der übergeordneten Klasse (Picture) } @@ -79,8 +79,6 @@ public class Player extends Picture implements KeyListener { // extends Picture pressed_up = false; pressed_down = false; - - } else { // ansonsten: // soll Pac-Man sich sobald er kann nach links bewegen @@ -117,10 +115,7 @@ public class Player extends Picture implements KeyListener { // extends Picture pressed_right = false; pressed_up = false; pressed_down = false; - - - - + } else { pressed_left = false; pressed_right = true; @@ -151,7 +146,7 @@ public class Player extends Picture implements KeyListener { // extends Picture pressed_right = false; pressed_up = false; pressed_down = false; - + } else { pressed_left = false; pressed_right = false; @@ -182,7 +177,7 @@ public class Player extends Picture implements KeyListener { // extends Picture pressed_right = false; pressed_up = false; pressed_down = false; - + } else { pressed_left = false; pressed_right = false; @@ -256,52 +251,55 @@ public class Player extends Picture implements KeyListener { // extends Picture this.movingTicks++; int aniFrames; aniFrames = ((this.movingTicks + 1) % 125 / 25); - + if (Dir == "Left") { if (aniFrames == 1 || aniFrames == 5) { - this.changeSauce("Pacman_Left1"); + this.changeSauce("Pac-Man/Pacman_Left1"); } else if (aniFrames == 2 || aniFrames == 4) { - this.changeSauce("Pacman_Left"); + this.changeSauce("Pac-Man/Pacman_Left"); } else if (aniFrames == 3) { - this.changeSauce("Pacman_Left3"); + this.changeSauce("Pac-Man/Pacman_Left3"); } - }if (Dir == "Right") { + } + if (Dir == "Right") { if (aniFrames == 1 || aniFrames == 5) { - this.changeSauce("Pacman_Right1"); + this.changeSauce("Pac-Man/Pacman_Right1"); } else if (aniFrames == 2 || aniFrames == 4) { - this.changeSauce("Pacman_Right"); + this.changeSauce("Pac-Man/Pacman_Right"); } else if (aniFrames == 3) { - this.changeSauce("Pacman_Right3"); + this.changeSauce("Pac-Man/Pacman_Right3"); } - }if (Dir == "Up") { + } + if (Dir == "Up") { if (aniFrames == 1 || aniFrames == 5) { - this.changeSauce("Pacman_Up1"); + this.changeSauce("Pac-Man/Pacman_Up1"); } else if (aniFrames == 2 || aniFrames == 4) { - this.changeSauce("Pacman_Up"); + this.changeSauce("Pac-Man/Pacman_Up"); } else if (aniFrames == 3) { - this.changeSauce("Pacman_Up3"); + this.changeSauce("Pac-Man/Pacman_Up3"); } - }if (Dir == "Down") { + } + if (Dir == "Down") { if (aniFrames == 1 || aniFrames == 5) { - this.changeSauce("Pacman_Down1"); + this.changeSauce("Pac-Man/Pacman_Down1"); } else if (aniFrames == 2 || aniFrames == 4) { - this.changeSauce("Pacman_Down"); + this.changeSauce("Pac-Man/Pacman_Down"); } else if (aniFrames == 3) { - this.changeSauce("Pacman_Down3"); + this.changeSauce("Pac-Man/Pacman_Down3"); }