diff --git a/assets/Map.txt b/assets/Map.txt index 3e47a5e..7e17f76 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -27,4 +27,4 @@ # ########## ## ########## # # ########## ## ########## # # # -############################ \ No newline at end of file +############################ diff --git a/assets/feared.png b/assets/feared.png new file mode 100644 index 0000000..c68d520 Binary files /dev/null and b/assets/feared.png differ diff --git a/bin/Game.class b/bin/Game.class index abcce5c..90b3a0b 100644 Binary files a/bin/Game.class and b/bin/Game.class differ diff --git a/bin/Ghost.class b/bin/Ghost.class index 0e00c2a..b0bffb5 100644 Binary files a/bin/Ghost.class and b/bin/Ghost.class differ diff --git a/src/Game.java b/src/Game.java index 707ce52..7975050 100644 --- a/src/Game.java +++ b/src/Game.java @@ -33,7 +33,7 @@ public class Game { @SuppressWarnings("unused") private long fps = 60; - private int windowSizeX = 800; // Größe des Frame in x-Richtung + private int windowSizeX = 880; // Größe des Frame in x-Richtung private int windowSizeY = 800; // Größe des Frame in y-Richtung private int frameLocationX = 100; // Position des Frame auf dem Bildschirm in x-Richtung @@ -124,7 +124,8 @@ public class Game { 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 + Map.bigpoints[j][i].setBounds(Map.bigpoints[j][i].xPos, Map.bigpoints[j][i].yPos, 20, 20); // Rendern + // des } } @@ -134,8 +135,17 @@ public class Game { lastT = System.nanoTime(); // delta time while (true) { // Hauptschleife - frames ++; - + frames++; + if (ghosts[0].feared == true) { + if (Ghost.fearedTimer != 0) { + Ghost.fearedTimer--; + + } else { + for (int i = 0; i < ghosts.length; i++) { + ghosts[i].feared = false; + } + } + } dt = System.nanoTime() - lastT; // delta time lastT = System.nanoTime(); // delta time @@ -204,9 +214,8 @@ public class Game { minn = HCost[j]; } } - - if ((frames % 2) != 0) { - for (int j = 0; j < 4; j++) { + + for (int j = 0; j < 4; j++) { if (HCost[j] == minn) { if (j == 0) { ghosts[i].right = true; @@ -235,10 +244,10 @@ public class Game { ghosts[i].left = false; ghosts[i].up = false; break; - } } } } + } // Kollision von Pac-Man mit Bricks: @@ -283,11 +292,32 @@ public class Game { Map.points[j][i] = null; - score++; + score += 150; scoreLabel.setText(Integer.toString(score)); - if(score == Map.maxScore) { - System.out.println("YOU WON!!!"); + + } + } + } + } + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + if (Map.bigpoints[j][i] != null) { + if (player.getPos('x', 0) < Map.bigpoints[j][i].xPos + 6 + && player.getPos('x', 0) > Map.bigpoints[j][i].xPos - 6 + && player.getPos('y', 0) < Map.bigpoints[j][i].yPos + 6 + && player.getPos('y', 0) > Map.bigpoints[j][i].yPos - 6) { + + Map.bigpoints[j][i].setBounds(0, 0, 0, 0); + + Map.bigpoints[j][i] = null; + + score += 1000; + scoreLabel.setText(Integer.toString(score)); + for (i = 0; i < 4; i++) { + ghosts[i].feared = true; + Ghost.fearedTimer = 1000; } + } } } @@ -300,19 +330,25 @@ public class Game { if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 20 && player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 20 && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 20 - && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) { + && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) + if (ghosts[0].feared) { - player.lives--; + ghosts[i].setPos('x', Map.ghost_posX[i]); + ghosts[i].setPos('y', Map.ghost_posY[i]); + score += 1000; + } else { + player.lives--; - liveLabels[player.lives].setBounds(0, 0, 0, 0); - if (player.lives == 0) { - System.exit(0); - } - - delay(200); - for (int j = 0; j < ghosts.length; j++) { - ghosts[j].setPos('x', Map.ghost_posX[j]); - ghosts[j].setPos('y', Map.ghost_posY[j]); + liveLabels[player.lives].setBounds(0, 0, 0, 0); + if (player.lives == 0) { + System.exit(0); + } + + delay(200); + for (int j = 0; j < ghosts.length; j++) { + ghosts[j].setPos('x', Map.ghost_posX[j]); + ghosts[j].setPos('y', Map.ghost_posY[j]); + } player.setPos('x', Map.pac_posX); player.setPos('y', Map.pac_posY); player.up = false; @@ -320,18 +356,42 @@ public class Game { player.right = false; player.left = false; } + } + + + fps = 1000000000 / dt; + // System.out.println("fps: " + fps); + + delay(delaytimer); // Ein delay zum Ende der Hauptschleife + + if (frames % 100 == 0) { + boolean empty = true; + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + if (Map.points[j][i] != null) { + empty = false; + } } } - fps = 1000000000 / dt; - - // System.out.println("fps: " + fps); - - delay(delaytimer); // Ein delay zum Ende der Hauptschleife - + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + if (Map.bigpoints[j][i] != null) { + empty = false; + } + } + } + if (empty) { + scoreLabel.setText("YOU WON"); + delay(1000); + System.exit(0); + } + } } } + + // Methode zum verzögern (warten) in ms public void delay(int time) { diff --git a/src/Ghost.java b/src/Ghost.java index 5769201..ae3485e 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -11,8 +11,10 @@ public class Ghost extends Picture { // Die public boolean down; public boolean left; public boolean right; - - private int HCost; + + public boolean feared = false; + public static int fearedTimer; + private double HCost; private int type; public Ghost(int type) { @@ -40,6 +42,7 @@ public class Ghost extends Picture { // Die } public int getHCost(Player player, int mod_x, int mod_y) { + if (!feared) { if (type == 0) { HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) @@ -54,9 +57,17 @@ public class Ghost extends Picture { // Die HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) + 100 - 10) / 20), 2)); } - return HCost; + + } + else { + HCost = 10 * (1 / (Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) + + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2)))); + } + + return (int) HCost; + + } - public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erwähnte delta time ins Spiel if (coordinate == 'x') { // Auslesen der 'x' - Koordinate: