geister töten mit respawn zeit

master
leventius imperatus 2020-06-07 15:42:46 +02:00
parent a9fd79860e
commit d910b4a191
14 changed files with 142 additions and 106 deletions

View File

@ -5,7 +5,7 @@
# # # #
# #### ## ######## ## #### # # #### ## ######## ## #### #
# #### ## ######## ## #### # # #### ## ######## ## #### #
# ## ## ## # # ##. ## .## #
###### ##### ## ##### ###### ###### ##### ## ##### ######
,,,,,# ##### ## ##### #,,,,, ,,,,,# ##### ## ##### #,,,,,
,,,,,# ## ## #,,,,, ,,,,,# ## ## #,,,,,
@ -23,7 +23,7 @@
#. ## P ## .# #. ## P ## .#
### ## ## ######## ## ## ### ### ## ## ######## ## ## ###
### ## ## ######## ## ## ### ### ## ## ######## ## ## ###
# ## ## ## # # ## .##. ## #
# ########## ## ########## # # ########## ## ########## #
# ########## ## ########## # # ########## ## ########## #
# # # #

10
bin/.gitignore vendored
View File

@ -1,10 +0,0 @@
/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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -133,12 +133,36 @@ public class Game {
} }
} }
} }
delay(30); delay(30);
lastT = System.nanoTime(); // delta time lastT = System.nanoTime(); // delta time
frame.setVisible(true); frame.setVisible(true);
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
while (true) { // Hauptschleife while (true) { // Hauptschleife
for (int i = 0; i < ghosts.length; i++) {
if (ghosts[i].getIsDead()) {
if (ghosts[i].getDeathTimer() != 0) {
ghosts[i].setDeathTimer(ghosts[i].getDeathTimer() - 1);
System.out.println(ghosts[i].getDeathTimer());
} else {
ghosts[i].setIsDead(false);
ghosts[i].setPos('x', Map.ghost_posX[i]);
ghosts[i].setPos('y', Map.ghost_posY[i]);
}
}
}
frames++; frames++;
if (ghosts[0].feared == true) { if (ghosts[0].feared == true) {
if (Ghost.fearedTimer != 0) { if (Ghost.fearedTimer != 0) {
@ -159,102 +183,103 @@ public class Game {
player.setLocation(player.getPos('x', dt), player.getPos('y', dt)); player.setLocation(player.getPos('x', dt), player.getPos('y', dt));
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
if (!ghosts[i].getIsDead()) {
ghost_possible[i][0] = false;
ghost_possible[i][1] = false;
ghost_possible[i][2] = false;
ghost_possible[i][3] = false;
ghost_possible[i][0] = false; if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null
ghost_possible[i][1] = false; && Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null)
ghost_possible[i][2] = false; || (ghosts[i].xPos + 10) % 20 != 0) {
ghost_possible[i][3] = false; ghost_possible[i][0] = true;
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) + 1] == null
&& Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) + 1] == null)
|| (ghosts[i].xPos + 10) % 20 != 0) {
ghost_possible[i][0] = true;
}
if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null
&& Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null)
|| (ghosts[i].xPos + 10) % 20 != 0) {
ghost_possible[i][1] = true;
}
if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null
&& Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null)
|| (ghosts[i].yPos + 10) % 20 != 0) {
ghost_possible[i][2] = true;
}
if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null
&& Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null)
|| (ghosts[i].yPos + 10) % 20 != 0) {
ghost_possible[i][3] = true;
}
HCost[0] = ghosts[i].getHCost(player, 1, 0);
HCost[1] = ghosts[i].getHCost(player, -1, 0);
HCost[2] = ghosts[i].getHCost(player, 0, -1);
HCost[3] = ghosts[i].getHCost(player, 0, 1);
//
int minn = 10000;
if (ghosts[i].up == true) {
HCost[3] = 10000;
}
if (ghosts[i].down == true) {
HCost[2] = 10000;
}
if (ghosts[i].left == true) {
HCost[0] = 10000;
}
if (ghosts[i].right == true) {
HCost[1] = 10000;
}
for (int j = 0; j < 4; j++) {
if (ghost_possible[i][j] == false) {
HCost[j] = 10500;
} }
} if ((Map.bricks[conv(ghosts[i].yPos)][conv(ghosts[i].xPos) - 1] == null
&& Map.bricks[conv(ghosts[i].yPos + 19)][conv(ghosts[i].xPos) - 1] == null)
|| (ghosts[i].xPos + 10) % 20 != 0) {
ghost_possible[i][1] = true;
for (int j = 0; j < 4; j++) {
if (minn > HCost[j]) {
minn = HCost[j];
} }
} if ((Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos)] == null
System.out.println(HCost[0]+ " "+HCost[1]+ " "+ HCost[2] + " "+HCost[3] ); && Map.bricks[conv(ghosts[i].yPos) - 1][conv(ghosts[i].xPos + 19)] == null)
for (int j = 0; j < 4; j++) { || (ghosts[i].yPos + 10) % 20 != 0) {
if (HCost[j] == minn) { ghost_possible[i][2] = true;
if (j == 0) { }
ghosts[i].right = true; if ((Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos)] == null
ghosts[i].left = false; && Map.bricks[conv(ghosts[i].yPos) + 1][conv(ghosts[i].xPos + 19)] == null)
ghosts[i].down = false; || (ghosts[i].yPos + 10) % 20 != 0) {
ghosts[i].up = false; ghost_possible[i][3] = true;
break; }
}
if (j == 1) { HCost[0] = ghosts[i].getHCost(player, 1, 0);
ghosts[i].left = true; HCost[1] = ghosts[i].getHCost(player, -1, 0);
ghosts[i].right = false; HCost[2] = ghosts[i].getHCost(player, 0, -1);
ghosts[i].down = false; HCost[3] = ghosts[i].getHCost(player, 0, 1);
ghosts[i].up = false; //
break; int minn = 10000;
}
if (j == 2) { if (ghosts[i].up == true) {
ghosts[i].up = true; HCost[3] = 10000;
ghosts[i].right = false; }
ghosts[i].left = false; if (ghosts[i].down == true) {
ghosts[i].down = false; HCost[2] = 10000;
break; }
} if (ghosts[i].left == true) {
if (j == 3) { HCost[0] = 10000;
ghosts[i].down = true; }
ghosts[i].right = false; if (ghosts[i].right == true) {
ghosts[i].left = false; HCost[1] = 10000;
ghosts[i].up = false; }
break;
for (int j = 0; j < 4; j++) {
if (ghost_possible[i][j] == false) {
HCost[j] = 10500;
} }
} }
}
for (int j = 0; j < 4; j++) {
if (minn > HCost[j]) {
minn = HCost[j];
}
}
// System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " +
// HCost[3]);
for (int j = 0; j < 4; j++) {
if (HCost[j] == minn) {
if (j == 0) {
ghosts[i].right = true;
ghosts[i].left = false;
ghosts[i].down = false;
ghosts[i].up = false;
break;
}
if (j == 1) {
ghosts[i].left = true;
ghosts[i].right = false;
ghosts[i].down = false;
ghosts[i].up = false;
break;
}
if (j == 2) {
ghosts[i].up = true;
ghosts[i].right = false;
ghosts[i].left = false;
ghosts[i].down = false;
break;
}
if (j == 3) {
ghosts[i].down = true;
ghosts[i].right = false;
ghosts[i].left = false;
ghosts[i].up = false;
break;
}
}
}
}
} }
// Kollision von Pac-Man mit Bricks: // Kollision von Pac-Man mit Bricks:
for (int i = 0; i < 35; i++) { // für jeden Brick for (int i = 0; i < 35; i++) { // für jeden Brick
for (int j = 0; j < 35; j++) { // für jeden Brick for (int j = 0; j < 35; j++) { // für jeden Brick
@ -363,10 +388,13 @@ public class Game {
&& player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 20 && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 20
&& player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20)
if (ghosts[0].feared) { if (ghosts[0].feared) {
ghosts[i].setIsDead(true);
ghosts[i].setPos('x', Map.ghost_posX[i]); ghosts[i].setDeathTimer(1000);
ghosts[i].setPos('y', Map.ghost_posY[i]); ghosts[i].setPos('x', -100);
ghosts[i].setPos('y', -100);
score += 1000; score += 1000;
System.out.println("Geist"+ i + " ist gestorben" + ghosts[i].getIsDead());
} else { } else {
player.lives--; player.lives--;

View File

@ -12,8 +12,10 @@ public class Ghost extends Picture { // Die
public boolean left; public boolean left;
public boolean right; public boolean right;
public boolean feared = false; public boolean feared;
public static int fearedTimer; public static int fearedTimer;
private int deathTimer;
private boolean isDead;
private double HCost; private double HCost;
private int type; private int type;
@ -36,7 +38,7 @@ public class Ghost extends Picture { // Die
} else if (type == 1) { } else if (type == 1) {
this.changeSauce("Pinky"); this.changeSauce("Pinky");
} }
} }
public void setPos(char coordinate, int newPos) { public void setPos(char coordinate, int newPos) {
@ -74,6 +76,22 @@ public class Ghost extends Picture { // Die
} }
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 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: