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
/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 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]);

View File

@ -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 {