diff --git a/bin/.gitignore b/bin/.gitignore index cc3ed02..277032d 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,2 +1,9 @@ -/Point.class +/Brick.class +/Game.class +/Ghost.class /Lives.class +/Main.class +/Map.class +/Picture.class +/Player.class +/Point.class 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 97fc00c..3e31477 100644 Binary files a/bin/Game.class and b/bin/Game.class differ diff --git a/bin/Ghost.class b/bin/Ghost.class index c6af23e..3e448ab 100644 Binary files a/bin/Ghost.class and b/bin/Ghost.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 e3855a7..aad37fc 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/src/Game.java b/src/Game.java index 4ca878b..fdfdbaa 100644 --- a/src/Game.java +++ b/src/Game.java @@ -28,7 +28,7 @@ public class Game { private JLabel liveLabels[]; - private int delaytimer = 12; + private int delaytimer = 4; @SuppressWarnings("unused") private long fps = 60; @@ -41,7 +41,7 @@ public class Game { // oben links (0|0) // nach rechts --> x wird größer // nach unten --> y wird größer - + public static int frames; int minn; int[] HCost = new int[4]; @@ -125,7 +125,8 @@ public class Game { lastT = System.nanoTime(); // delta time while (true) { // Hauptschleife - + frames ++; + dt = System.nanoTime() - lastT; // delta time lastT = System.nanoTime(); // delta time @@ -194,8 +195,9 @@ public class Game { minn = HCost[j]; } } - - for (int j = 0; j < 4; j++) { + + if ((frames % 2) != 0) { + for (int j = 0; j < 4; j++) { if (HCost[j] == minn) { if (j == 0) { ghosts[i].right = true; @@ -224,10 +226,10 @@ public class Game { ghosts[i].left = false; ghosts[i].up = false; break; + } } } } - } // Kollision von Pac-Man mit Bricks: @@ -297,7 +299,7 @@ public class Game { if (player.lives == 0) { System.exit(0); } - System.out.println(player.lives); + delay(200); for (int j = 0; j < ghosts.length; j++) { ghosts[j].setPos('x', Map.ghost_posX[j]); diff --git a/src/Ghost.java b/src/Ghost.java index d87b090..1023d09 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -11,20 +11,21 @@ public class Ghost extends Picture { // Die public boolean down; public boolean left; public boolean right; - + private int HCost; - - public Ghost(int index) { - + private int type; + public Ghost(int type) { + + super("Pinky"); // Aufrufen der übergeordneten Klasse - + this.type = type; // xPos = 150 + 40 * index; - if (index == 0) { + if (type == 0) { this.changeSauce("Blinky"); - } else if (index == 2) { + } else if (type == 2) { this.changeSauce("Inky"); - } else if (index == 3) { + } else if (type == 3) { this.changeSauce("Clyde"); } @@ -39,27 +40,45 @@ public class Ghost extends Picture { // Die } public int getHCost(Player player, int mod_x, int mod_y) { + if (type == 0) { - 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) - 10) / 20), 2)); - + 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) - 10) / 20), 2)); + } else if (type == 1) { + HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2) + + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2)); + } else if (type == 2) { + HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((300 - 10 + 80) / 20), 2) + + Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2)); + } else if (type == 3) { + 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; } public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erwähnte delta time ins Spiel if (coordinate == 'x') { // Auslesen der 'x' - Koordinate: - if (left && dt != 0) { - xPos -= 1; - } else if (right && dt != 0) { - xPos += 1; + if (left && dt != 0 && (Game.frames % 3) == 0) { + + xPos -= 1; + + } else if (right && dt != 0 && (Game.frames % 3) == 0) { + + xPos += 1; + } return (int) xPos; } else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate: - if (down && dt != 0) { - yPos += 1; - } else if (up && dt != 0) { - yPos -= 1; + if (down && dt != 0 && (Game.frames % 3) == 0) { + + yPos += 1; + + } else if (up && dt != 0 && (Game.frames % 3) == 0) { + + yPos -= 1; + } return (int) yPos; // (int) } else {