Geister langsamer

master
leventius imperatus 2020-06-06 16:14:03 +02:00
parent 4ee6c9b8d4
commit be5b9617b5
10 changed files with 55 additions and 27 deletions

9
bin/.gitignore vendored
View File

@ -1,2 +1,9 @@
/Point.class /Brick.class
/Game.class
/Ghost.class
/Lives.class /Lives.class
/Main.class
/Map.class
/Picture.class
/Player.class
/Point.class

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -28,7 +28,7 @@ public class Game {
private JLabel liveLabels[]; private JLabel liveLabels[];
private int delaytimer = 12; private int delaytimer = 4;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private long fps = 60; private long fps = 60;
@ -41,7 +41,7 @@ public class Game {
// oben links (0|0) // oben links (0|0)
// nach rechts --> x wird größer // nach rechts --> x wird größer
// nach unten --> y wird größer // nach unten --> y wird größer
public static int frames;
int minn; int minn;
int[] HCost = new int[4]; int[] HCost = new int[4];
@ -125,6 +125,7 @@ public class Game {
lastT = System.nanoTime(); // delta time lastT = System.nanoTime(); // delta time
while (true) { // Hauptschleife while (true) { // Hauptschleife
frames ++;
dt = System.nanoTime() - lastT; // delta time dt = System.nanoTime() - lastT; // delta time
lastT = System.nanoTime(); // delta time lastT = System.nanoTime(); // delta time
@ -195,7 +196,8 @@ public class Game {
} }
} }
for (int j = 0; j < 4; j++) { if ((frames % 2) != 0) {
for (int j = 0; j < 4; j++) {
if (HCost[j] == minn) { if (HCost[j] == minn) {
if (j == 0) { if (j == 0) {
ghosts[i].right = true; ghosts[i].right = true;
@ -224,10 +226,10 @@ public class Game {
ghosts[i].left = false; ghosts[i].left = false;
ghosts[i].up = false; ghosts[i].up = false;
break; break;
}
} }
} }
} }
} }
// Kollision von Pac-Man mit Bricks: // Kollision von Pac-Man mit Bricks:
@ -297,7 +299,7 @@ public class Game {
if (player.lives == 0) { if (player.lives == 0) {
System.exit(0); System.exit(0);
} }
System.out.println(player.lives);
delay(200); delay(200);
for (int j = 0; j < ghosts.length; j++) { for (int j = 0; j < ghosts.length; j++) {
ghosts[j].setPos('x', Map.ghost_posX[j]); ghosts[j].setPos('x', Map.ghost_posX[j]);

View File

@ -13,18 +13,19 @@ public class Ghost extends Picture { // Die
public boolean right; public boolean right;
private int HCost; private int HCost;
private int type;
public Ghost(int type) {
public Ghost(int index) {
super("Pinky"); // Aufrufen der übergeordneten Klasse super("Pinky"); // Aufrufen der übergeordneten Klasse
this.type = type;
// xPos = 150 + 40 * index; // xPos = 150 + 40 * index;
if (index == 0) { if (type == 0) {
this.changeSauce("Blinky"); this.changeSauce("Blinky");
} else if (index == 2) { } else if (type == 2) {
this.changeSauce("Inky"); this.changeSauce("Inky");
} else if (index == 3) { } else if (type == 3) {
this.changeSauce("Clyde"); this.changeSauce("Clyde");
} }
@ -39,27 +40,45 @@ public class Ghost extends Picture { // Die
} }
public int getHCost(Player player, int mod_x, int mod_y) { 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) 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)); + 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; return HCost;
} }
public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erwähnte delta time ins Spiel 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 (coordinate == 'x') { // Auslesen der 'x' - Koordinate:
if (left && dt != 0) { if (left && dt != 0 && (Game.frames % 3) == 0) {
xPos -= 1;
} else if (right && dt != 0) { xPos -= 1;
xPos += 1;
} else if (right && dt != 0 && (Game.frames % 3) == 0) {
xPos += 1;
} }
return (int) xPos; return (int) xPos;
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate: } else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
if (down && dt != 0) { if (down && dt != 0 && (Game.frames % 3) == 0) {
yPos += 1;
} else if (up && dt != 0) { yPos += 1;
yPos -= 1;
} else if (up && dt != 0 && (Game.frames % 3) == 0) {
yPos -= 1;
} }
return (int) yPos; // (int) return (int) yPos; // (int)
} else { } else {