change sauce und geister ki verändert

master
leventius imperatus 2020-06-07 14:09:46 +02:00
parent b909505fb1
commit 76bb289115
6 changed files with 101 additions and 62 deletions

7
bin/.gitignore vendored
View File

@ -1,3 +1,10 @@
/BigPoint.class /BigPoint.class
/Brick.class
/Game.class
/Ghost.class
/Lives.class /Lives.class
/Main.class
/Map.class
/Picture.class
/Player.class
/Point.class /Point.class

Binary file not shown.

Binary file not shown.

View File

@ -53,7 +53,6 @@ public class Game {
ImageIcon img = new ImageIcon("assets/Pacman_Right.png"); ImageIcon img = new ImageIcon("assets/Pacman_Right.png");
frame.setIconImage(img.getImage()); frame.setIconImage(img.getImage());
panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert
ghosts = new Ghost[4]; // 4 Geister ghosts = new Ghost[4]; // 4 Geister
@ -147,6 +146,7 @@ public class Game {
} else { } else {
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
ghosts[i].feared = false; ghosts[i].feared = false;
ghosts[i].ogSauce();
} }
} }
} }
@ -320,6 +320,32 @@ public class Game {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
ghosts[i].feared = true; ghosts[i].feared = true;
Ghost.fearedTimer = 1000; Ghost.fearedTimer = 1000;
ghosts[i].changeSauce("feared");
if (ghosts[i].left) {
ghosts[i].right = true;
ghosts[i].left = false;
ghosts[i].down = false;
ghosts[i].up = false;
} else if (ghosts[i].right) {
ghosts[i].left = true;
ghosts[i].right = false;
ghosts[i].down = false;
ghosts[i].up = false;
} else if (ghosts[i].down) {
ghosts[i].up = true;
ghosts[i].right = false;
ghosts[i].left = false;
ghosts[i].down = false;
} else if (ghosts[i].up) {
ghosts[i].down = true;
ghosts[i].right = false;
ghosts[i].left = false;
ghosts[i].up = false;
}
} }
} }
@ -361,41 +387,38 @@ public class Game {
player.left = false; player.left = false;
} }
} }
fps = 1000000000 / dt;
// System.out.println("fps: " + fps); fps = 1000000000 / dt;
delay(delaytimer); // Ein delay zum Ende der Hauptschleife // System.out.println("fps: " + fps);
if (frames % 100 == 0) { delay(delaytimer); // Ein delay zum Ende der Hauptschleife
boolean empty = true;
for (int i = 0; i < 35; i++) { if (frames % 100 == 0) {
for (int j = 0; j < 35; j++) { boolean empty = true;
if (Map.points[j][i] != null) { for (int i = 0; i < 35; i++) {
empty = false; for (int j = 0; j < 35; j++) {
if (Map.points[j][i] != null) {
empty = false;
}
} }
} }
} for (int i = 0; i < 35; i++) {
for (int i = 0; i < 35; i++) { for (int j = 0; j < 35; j++) {
for (int j = 0; j < 35; j++) { if (Map.bigpoints[j][i] != null) {
if (Map.bigpoints[j][i] != null) { empty = false;
empty = false; }
} }
} }
if (empty) {
scoreLabel.setText("YOU WON");
delay(1000);
System.exit(0);
}
} }
if (empty) {
scoreLabel.setText("YOU WON");
delay(1000);
System.exit(0);
}
}
} }
} }
// Methode zum verzögern (warten) in ms // Methode zum verzögern (warten) in ms
public void delay(int time) { public void delay(int time) {

View File

@ -11,26 +11,32 @@ public class Ghost extends Picture { // Die
public boolean down; public boolean down;
public boolean left; public boolean left;
public boolean right; public boolean right;
public boolean feared = false; public boolean feared = false;
public static int fearedTimer; public static int fearedTimer;
private double HCost; private double HCost;
private int type; private int type;
public Ghost(int type) { public Ghost(int type) {
super("Pinky"); // Aufrufen der übergeordneten Klasse super("Pinky"); // Aufrufen der übergeordneten Klasse
this.type = type; this.type = type;
// xPos = 150 + 40 * index; // xPos = 150 + 40 * index;
this.ogSauce();
}
public void ogSauce() {
if (type == 0) { if (type == 0) {
this.changeSauce("Blinky"); this.changeSauce("Blinky");
} else if (type == 2) { } else if (type == 2) {
this.changeSauce("Inky"); this.changeSauce("Inky");
} else if (type == 3) { } else if (type == 3) {
this.changeSauce("Clyde"); this.changeSauce("Clyde");
} else if (type == 1) {
this.changeSauce("Pinky");
} }
} }
public void setPos(char coordinate, int newPos) { public void setPos(char coordinate, int newPos) {
@ -43,53 +49,53 @@ 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 (!feared) { if (!feared) {
if (type == 0) { 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) { } else if (type == 1) {
HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2) HCost = (int) Math
+ Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2)); .sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2)
} else if (type == 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) - ((300 - 10 + 80) / 20), 2) } else if (type == 2) {
+ Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2)); HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((300 - 10 + 80) / 20), 2)
} else if (type == 3) { + Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2));
HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) } else if (type == 3) {
+ Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) + 100 - 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));
}
}
else { } else {
HCost = 10 * (1 / (Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) HCost = 10 * (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)))); + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2))));
} }
return (int) HCost; return (int) 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 && Game.frames % 4 == 0) { if (left && dt != 0 && Game.frames % 4 == 0) {
xPos -= 1; xPos -= 1;
} else if (right && dt != 0 && Game.frames % 4 == 0) { } else if (right && dt != 0 && Game.frames % 4 == 0) {
xPos += 1; 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 && Game.frames % 4 == 0) { if (down && dt != 0 && Game.frames % 4 == 0) {
yPos += 1; yPos += 1;
} else if (up && dt != 0 && Game.frames % 4 == 0) { } else if (up && dt != 0 && Game.frames % 4 == 0) {
yPos -= 1; yPos -= 1;
} }
return (int) yPos; // (int) return (int) yPos; // (int)
} else { } else {

View File

@ -1,6 +1,9 @@
public class Lives extends Picture{ public class Lives extends Picture{
private static final long serialVersionUID = -4715442447789971450L;
public Lives() { public Lives() {
super("heart"); super("heart");
} }