fix von ghost pathing

master
leventius imperatus 2020-06-07 16:12:00 +02:00
parent d910b4a191
commit 534748e313
4 changed files with 43 additions and 36 deletions

Binary file not shown.

Binary file not shown.

View File

@ -158,7 +158,6 @@ public class Game {
ghosts[i].setPos('x', Map.ghost_posX[i]); ghosts[i].setPos('x', Map.ghost_posX[i]);
ghosts[i].setPos('y', Map.ghost_posY[i]); ghosts[i].setPos('y', Map.ghost_posY[i]);
} }
} }
} }
@ -219,16 +218,16 @@ public class Game {
// //
int minn = 10000; int minn = 10000;
if (ghosts[i].up == true) { if (ghosts[i].dire == 2) {
HCost[3] = 10000; HCost[3] = 10000;
} }
if (ghosts[i].down == true) { if (ghosts[i].dire == 3) {
HCost[2] = 10000; HCost[2] = 10000;
} }
if (ghosts[i].left == true) { if (ghosts[i].dire == 1) {
HCost[0] = 10000; HCost[0] = 10000;
} }
if (ghosts[i].right == true) { if (ghosts[i].dire == 0) {
HCost[1] = 10000; HCost[1] = 10000;
} }
@ -247,33 +246,39 @@ public class Game {
// HCost[3]); // HCost[3]);
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
if (HCost[j] == minn) { if (HCost[j] == minn) {
if (j == 0) { if (frames % 4 == 0) {
ghosts[i].right = true; if (j == 0) {
ghosts[i].left = false; ghosts[i].right = true;
ghosts[i].down = false; ghosts[i].left = false;
ghosts[i].up = false; ghosts[i].down = false;
break; ghosts[i].up = false;
} ghosts[i].dire = 0;
if (j == 1) { break;
ghosts[i].left = true; }
ghosts[i].right = false; if (j == 1) {
ghosts[i].down = false; ghosts[i].left = true;
ghosts[i].up = false; ghosts[i].right = false;
break; ghosts[i].down = false;
} ghosts[i].up = false;
if (j == 2) { ghosts[i].dire = 1;
ghosts[i].up = true; break;
ghosts[i].right = false; }
ghosts[i].left = false; if (j == 2) {
ghosts[i].down = false; ghosts[i].up = true;
break; ghosts[i].right = false;
} ghosts[i].left = false;
if (j == 3) { ghosts[i].down = false;
ghosts[i].down = true; ghosts[i].dire = 2;
ghosts[i].right = false; break;
ghosts[i].left = false; }
ghosts[i].up = false; if (j == 3) {
break; ghosts[i].down = true;
ghosts[i].right = false;
ghosts[i].left = false;
ghosts[i].up = false;
ghosts[i].dire = 3;
break;
}
} }
} }
} }
@ -393,7 +398,7 @@ public class Game {
ghosts[i].setPos('x', -100); ghosts[i].setPos('x', -100);
ghosts[i].setPos('y', -100); ghosts[i].setPos('y', -100);
score += 1000; score += 1000;
System.out.println("Geist"+ i + " ist gestorben" + ghosts[i].getIsDead()); System.out.println("Geist" + i + " ist gestorben" + ghosts[i].getIsDead());
} else { } else {
player.lives--; player.lives--;

View File

@ -12,6 +12,8 @@ public class Ghost extends Picture { // Die
public boolean left; public boolean left;
public boolean right; public boolean right;
public int dire;
public boolean feared; public boolean feared;
public static int fearedTimer; public static int fearedTimer;
private int deathTimer; private int deathTimer;
@ -60,8 +62,8 @@ public class Ghost extends Picture { // Die
.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2) .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)); + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2));
} else if (type == 2) { } else if (type == 2) {
HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((250 - 10 + 80) / 20), 2) HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((200 - 10 + 80) / 20), 2)
+ Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2)); + Math.pow((((yPos - 10) / 20) + mod_y) - ((200 - 10) / 20), 2));
} else if (type == 3) { } else if (type == 3) {
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) + 100 - 10) / 20), 2)); + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) + 100 - 10) / 20), 2));