129 lines
3.2 KiB
Java
129 lines
3.2 KiB
Java
// Diese Klasse stellt die einzelnen Geister dar.
|
|
|
|
public class Ghost extends Picture { // Die übergeordnete Klasse ist Picture
|
|
|
|
private static final long serialVersionUID = -5352006665147359473L;
|
|
|
|
public float xPos;
|
|
public float yPos;
|
|
|
|
public boolean up;
|
|
public boolean down;
|
|
public boolean left;
|
|
public boolean right;
|
|
|
|
public int dire;
|
|
|
|
public static int offFrames = 4;
|
|
public boolean feared;
|
|
public static int fearedTimer;
|
|
private int deathTimer;
|
|
private boolean isDead;
|
|
private double HCost;
|
|
private int type;
|
|
|
|
public Ghost(int type) {
|
|
|
|
super("Geister/Pinky"); // Aufrufen der übergeordneten Klasse
|
|
this.type = type;
|
|
// xPos = 150 + 40 * index;
|
|
|
|
this.ogSauce();
|
|
}
|
|
|
|
public void ogSauce() {
|
|
if (type == 0) {
|
|
this.changeSauce("Geister/Blinky");
|
|
} else if (type == 2) {
|
|
this.changeSauce("Geister/Inky");
|
|
} else if (type == 3) {
|
|
this.changeSauce("Geister/Clyde");
|
|
} else if (type == 1) {
|
|
this.changeSauce("Geister/Pinky");
|
|
}
|
|
|
|
}
|
|
|
|
public void setPos(char coordinate, int newPos) {
|
|
if (coordinate == 'x') {
|
|
xPos = newPos;
|
|
} else if (coordinate == 'y') {
|
|
yPos = newPos;
|
|
}
|
|
}
|
|
|
|
public int getHCost(Player player, int mod_x, int mod_y) {
|
|
if (!feared) {
|
|
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));
|
|
} 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) - ((200 - 10 + 80) / 20), 2)
|
|
+ Math.pow((((yPos - 10) / 20) + mod_y) - ((200 - 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));
|
|
}
|
|
|
|
} else {
|
|
HCost = 100
|
|
* (1 / (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))));
|
|
}
|
|
|
|
return (int) HCost;
|
|
|
|
}
|
|
|
|
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:
|
|
if (left && dt != 0 && Game.frames % offFrames == 0) {
|
|
|
|
xPos -= 1;
|
|
|
|
} else if (right && dt != 0 && Game.frames % offFrames == 0) {
|
|
|
|
xPos += 1;
|
|
|
|
}
|
|
return (int) xPos;
|
|
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
|
|
if (down && dt != 0 && Game.frames % offFrames == 0) {
|
|
|
|
yPos += 1;
|
|
|
|
} else if (up && dt != 0 && Game.frames % offFrames == 0) {
|
|
|
|
yPos -= 1;
|
|
|
|
}
|
|
return (int) yPos;
|
|
} else {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
}
|