diff --git a/assets/Map.txt b/assets/Map.txt index 7e17f76..b30ecb7 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -5,7 +5,7 @@ # # # #### ## ######## ## #### # # #### ## ######## ## #### # -# ## ## ## # +# ##. ## .## # ###### ##### ## ##### ###### ,,,,,# ##### ## ##### #,,,,, ,,,,,# ## ## #,,,,, @@ -23,7 +23,7 @@ #. ## P ## .# ### ## ## ######## ## ## ### ### ## ## ######## ## ## ### -# ## ## ## # +# ## .##. ## # # ########## ## ########## # # ########## ## ########## # # # diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index 0007eb6..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/BigPoint.class -/Brick.class -/Game.class -/Ghost.class -/Lives.class -/Main.class -/Map.class -/Picture.class -/Player.class -/Point.class diff --git a/bin/BigPoint.class b/bin/BigPoint.class index b34987f..c92c3e0 100644 Binary files a/bin/BigPoint.class and b/bin/BigPoint.class differ diff --git a/bin/Brick.class b/bin/Brick.class index 50ef0ed..98f1c69 100644 Binary files a/bin/Brick.class and b/bin/Brick.class differ diff --git a/bin/Game.class b/bin/Game.class index fee8ec6..5917123 100644 Binary files a/bin/Game.class and b/bin/Game.class differ diff --git a/bin/Ghost.class b/bin/Ghost.class index e9ca2d5..d7ec4e1 100644 Binary files a/bin/Ghost.class and b/bin/Ghost.class differ diff --git a/bin/Lives.class b/bin/Lives.class index a774fe7..f55526b 100644 Binary files a/bin/Lives.class and b/bin/Lives.class differ diff --git a/bin/Main.class b/bin/Main.class index 1a83356..ef3f066 100644 Binary files a/bin/Main.class and b/bin/Main.class differ diff --git a/bin/Map.class b/bin/Map.class index a288e72..6541853 100644 Binary files a/bin/Map.class and b/bin/Map.class differ diff --git a/bin/Picture.class b/bin/Picture.class index f720bca..3737254 100644 Binary files a/bin/Picture.class and b/bin/Picture.class differ diff --git a/bin/Player.class b/bin/Player.class index daa323b..56c9ae4 100644 Binary files a/bin/Player.class and b/bin/Player.class differ diff --git a/bin/Point.class b/bin/Point.class index 8431eb4..b863839 100644 Binary files a/bin/Point.class and b/bin/Point.class differ diff --git a/src/Game.java b/src/Game.java index c845e2d..d638797 100644 --- a/src/Game.java +++ b/src/Game.java @@ -133,12 +133,36 @@ public class Game { } } } - + delay(30); lastT = System.nanoTime(); // delta time - + frame.setVisible(true); + + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + // ----------------------------------------------------------------------------------------------------------------------------------------------------- + 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); + System.out.println(ghosts[i].getDeathTimer()); + } 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 (Ghost.fearedTimer != 0) { @@ -159,102 +183,103 @@ public class Game { player.setLocation(player.getPos('x', dt), player.getPos('y', dt)); for (int i = 0; i < ghosts.length; i++) { + if (!ghosts[i].getIsDead()) { + ghost_possible[i][0] = false; + ghost_possible[i][1] = false; + ghost_possible[i][2] = false; + ghost_possible[i][3] = false; - ghost_possible[i][0] = false; - ghost_possible[i][1] = false; - ghost_possible[i][2] = false; - ghost_possible[i][3] = false; + if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null + && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null) + || (ghosts[i].xPos + 10) % 20 != 0) { + ghost_possible[i][0] = true; - if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null - && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null) - || (ghosts[i].xPos + 10) % 20 != 0) { - ghost_possible[i][0] = true; - - } - if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null - && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null) - || (ghosts[i].xPos + 10) % 20 != 0) { - ghost_possible[i][1] = true; - - } - if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null - && Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null) - || (ghosts[i].yPos + 10) % 20 != 0) { - ghost_possible[i][2] = true; - } - if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null - && Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null) - || (ghosts[i].yPos + 10) % 20 != 0) { - ghost_possible[i][3] = true; - } - - HCost[0] = ghosts[i].getHCost(player, 1, 0); - HCost[1] = ghosts[i].getHCost(player, -1, 0); - HCost[2] = ghosts[i].getHCost(player, 0, -1); - HCost[3] = ghosts[i].getHCost(player, 0, 1); - // - int minn = 10000; - - if (ghosts[i].up == true) { - HCost[3] = 10000; - } - if (ghosts[i].down == true) { - HCost[2] = 10000; - } - if (ghosts[i].left == true) { - HCost[0] = 10000; - } - if (ghosts[i].right == true) { - HCost[1] = 10000; - } - - for (int j = 0; j < 4; j++) { - if (ghost_possible[i][j] == false) { - HCost[j] = 10500; } - } + if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null + && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null) + || (ghosts[i].xPos + 10) % 20 != 0) { + ghost_possible[i][1] = true; - for (int j = 0; j < 4; j++) { - if (minn > HCost[j]) { - minn = HCost[j]; } - } - System.out.println(HCost[0]+ " "+HCost[1]+ " "+ HCost[2] + " "+HCost[3] ); - for (int j = 0; j < 4; j++) { - if (HCost[j] == minn) { - if (j == 0) { - ghosts[i].right = true; - ghosts[i].left = false; - ghosts[i].down = false; - ghosts[i].up = false; - break; - } - if (j == 1) { - ghosts[i].left = true; - ghosts[i].right = false; - ghosts[i].down = false; - ghosts[i].up = false; - break; - } - if (j == 2) { - ghosts[i].up = true; - ghosts[i].right = false; - ghosts[i].left = false; - ghosts[i].down = false; - break; - } - if (j == 3) { - ghosts[i].down = true; - ghosts[i].right = false; - ghosts[i].left = false; - ghosts[i].up = false; - break; + if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null + && Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null) + || (ghosts[i].yPos + 10) % 20 != 0) { + ghost_possible[i][2] = true; + } + if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null + && Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null) + || (ghosts[i].yPos + 10) % 20 != 0) { + ghost_possible[i][3] = true; + } + + HCost[0] = ghosts[i].getHCost(player, 1, 0); + HCost[1] = ghosts[i].getHCost(player, -1, 0); + HCost[2] = ghosts[i].getHCost(player, 0, -1); + HCost[3] = ghosts[i].getHCost(player, 0, 1); + // + int minn = 10000; + + if (ghosts[i].up == true) { + HCost[3] = 10000; + } + if (ghosts[i].down == true) { + HCost[2] = 10000; + } + if (ghosts[i].left == true) { + HCost[0] = 10000; + } + if (ghosts[i].right == true) { + HCost[1] = 10000; + } + + for (int j = 0; j < 4; j++) { + if (ghost_possible[i][j] == false) { + HCost[j] = 10500; } } - } + for (int j = 0; j < 4; j++) { + if (minn > HCost[j]) { + minn = HCost[j]; + } + } + // System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " + + // HCost[3]); + for (int j = 0; j < 4; j++) { + if (HCost[j] == minn) { + if (j == 0) { + ghosts[i].right = true; + ghosts[i].left = false; + ghosts[i].down = false; + ghosts[i].up = false; + break; + } + if (j == 1) { + ghosts[i].left = true; + ghosts[i].right = false; + ghosts[i].down = false; + ghosts[i].up = false; + break; + } + if (j == 2) { + ghosts[i].up = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].down = false; + break; + } + if (j == 3) { + ghosts[i].down = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].up = false; + break; + } + } + } + + } } - // Kollision von Pac-Man mit Bricks: for (int i = 0; i < 35; i++) { // für jeden Brick for (int j = 0; j < 35; j++) { // für jeden Brick @@ -363,10 +388,13 @@ public class Game { && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 20 && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) if (ghosts[0].feared) { - - ghosts[i].setPos('x', Map.ghost_posX[i]); - ghosts[i].setPos('y', Map.ghost_posY[i]); + ghosts[i].setIsDead(true); + ghosts[i].setDeathTimer(1000); + ghosts[i].setPos('x', -100); + ghosts[i].setPos('y', -100); score += 1000; + System.out.println("Geist"+ i + " ist gestorben" + ghosts[i].getIsDead()); + } else { player.lives--; diff --git a/src/Ghost.java b/src/Ghost.java index 829aaaa..deeffa8 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -12,8 +12,10 @@ public class Ghost extends Picture { // Die public boolean left; public boolean right; - public boolean feared = false; + public boolean feared; public static int fearedTimer; + private int deathTimer; + private boolean isDead; private double HCost; private int type; @@ -36,7 +38,7 @@ public class Ghost extends Picture { // Die } else if (type == 1) { this.changeSauce("Pinky"); } - + } public void setPos(char coordinate, int newPos) { @@ -74,6 +76,22 @@ public class Ghost extends Picture { // Die } + public void setDeathTimer(int amount) { + this.deathTimer = amount; + } + + public int getDeathTimer() { + return (int) this.deathTimer; + } + + public void setIsDead(boolean b) { + this.isDead = b; + } + + public boolean getIsDead() { + return this.isDead; + } + public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erwähnte delta time ins Spiel if (coordinate == 'x') { // Auslesen der 'x' - Koordinate: