Pac-Man/src/Ghost.java

87 lines
1.8 KiB
Java
Raw Normal View History

2020-02-17 16:29:50 +01:00
// Diese Klasse stellt die einzelnen Geister dar.
public class Ghost extends Picture { // Die <20>bergeordnete Klasse ist Picture
private static final long serialVersionUID = -5352006665147359473L;
2020-06-04 19:54:41 +02:00
public int xPos;
public int yPos;
2020-06-04 19:54:41 +02:00
public boolean up;
public boolean down;
public boolean left;
public boolean right;
//private float speed = 0.00000007f;
private int HCost;
2020-02-17 16:29:50 +01:00
public Ghost(int index) {
super("Pinky"); // Aufrufen der <20>bergeordneten Klasse
2020-04-30 21:18:21 +02:00
// xPos = 150 + 40 * index;
2020-02-17 16:29:50 +01:00
if (index == 0) {
this.changeSauce("Blinky");
} else if (index == 2) {
this.changeSauce("Inky");
} else if (index == 3) {
this.changeSauce("Clyde");
}
}
2020-06-04 19:54:41 +02:00
2020-02-17 16:29:50 +01:00
public void setPos(char coordinate, int newPos) {
if (coordinate == 'x') {
xPos = newPos;
2020-04-30 21:18:21 +02:00
} else if (coordinate == 'y') {
2020-02-17 16:29:50 +01:00
yPos = newPos;
}
}
2020-06-04 19:54:41 +02:00
/*
public void setDirection(String dir) {
direction = dir;
}
2020-06-04 19:54:41 +02:00
public String getDirection() {
return direction;
}
2020-06-04 19:54:41 +02:00
*/
public int getHCost(Player player, int mod_x, int mod_y) {
2020-06-04 19:54:41 +02:00
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));
return HCost;
}
2020-05-21 16:39:25 +02:00
2020-06-04 19:54:41 +02:00
public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erw<72>hnte delta time ins Spiel
if (coordinate == 'x') { // Auslesen der 'x' - Koordinate:
if (left && dt != 0) {
// xPos -= speed * dt;
xPos -= 1;
} else if (right && dt != 0) {
// xPos += speed * dt;
xPos += 1;
}
return (int) xPos;
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
if (down && dt != 0) {
// yPos += speed * dt;
yPos += 1;
} else if (up && dt != 0) {
// yPos -= speed * dt;
yPos -= 1;
}
return (int) yPos; //(int)
} else {
return -1;
}
}
2020-02-17 16:29:50 +01:00
}