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
/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.

View File

@ -53,7 +53,6 @@ public class Game {
ImageIcon img = new ImageIcon("assets/Pacman_Right.png");
frame.setIconImage(img.getImage());
panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert
ghosts = new Ghost[4]; // 4 Geister
@ -147,6 +146,7 @@ public class Game {
} else {
for (int i = 0; i < ghosts.length; i++) {
ghosts[i].feared = false;
ghosts[i].ogSauce();
}
}
}
@ -320,6 +320,32 @@ public class Game {
for (i = 0; i < 4; i++) {
ghosts[i].feared = true;
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;
}
}
}
@ -362,40 +388,37 @@ public class Game {
}
}
fps = 1000000000 / dt;
fps = 1000000000 / dt;
// System.out.println("fps: " + fps);
// System.out.println("fps: " + fps);
delay(delaytimer); // Ein delay zum Ende der Hauptschleife
delay(delaytimer); // Ein delay zum Ende der Hauptschleife
if (frames % 100 == 0) {
boolean empty = true;
for (int i = 0; i < 35; i++) {
for (int j = 0; j < 35; j++) {
if (Map.points[j][i] != null) {
empty = false;
if (frames % 100 == 0) {
boolean empty = true;
for (int i = 0; i < 35; i++) {
for (int j = 0; j < 35; j++) {
if (Map.points[j][i] != null) {
empty = false;
}
}
}
}
for (int i = 0; i < 35; i++) {
for (int j = 0; j < 35; j++) {
if (Map.bigpoints[j][i] != null) {
empty = false;
for (int i = 0; i < 35; i++) {
for (int j = 0; j < 35; j++) {
if (Map.bigpoints[j][i] != null) {
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
public void delay(int time) {

View File

@ -16,19 +16,25 @@ public class Ghost extends Picture { // Die
public static int fearedTimer;
private double HCost;
private int type;
public Ghost(int type) {
public Ghost(int type) {
super("Pinky"); // Aufrufen der übergeordneten Klasse
this.type = type;
// xPos = 150 + 40 * index;
this.ogSauce();
}
public void ogSauce() {
if (type == 0) {
this.changeSauce("Blinky");
} else if (type == 2) {
this.changeSauce("Inky");
} else if (type == 3) {
this.changeSauce("Clyde");
} else if (type == 1) {
this.changeSauce("Pinky");
}
}
@ -43,52 +49,52 @@ public class Ghost extends Picture { // Die
public int getHCost(Player player, int mod_x, int mod_y) {
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)
+ 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));
}
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));
}
}
else {
HCost = 10 * (1 / (Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2)
} else {
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))));
}
return (int) 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 && Game.frames % 4 == 0) {
xPos -= 1;
xPos -= 1;
} else if (right && dt != 0 && Game.frames % 4 == 0) {
xPos += 1;
xPos += 1;
}
return (int) xPos;
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
if (down && dt != 0 && Game.frames % 4 == 0) {
yPos += 1;
yPos += 1;
} else if (up && dt != 0 && Game.frames % 4 == 0) {
yPos -= 1;
yPos -= 1;
}
return (int) yPos; // (int)

View File

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