geister töten mit respawn zeit
parent
a9fd79860e
commit
d910b4a191
|
@ -5,7 +5,7 @@
|
|||
# #
|
||||
# #### ## ######## ## #### #
|
||||
# #### ## ######## ## #### #
|
||||
# ## ## ## #
|
||||
# ##. ## .## #
|
||||
###### ##### ## ##### ######
|
||||
,,,,,# ##### ## ##### #,,,,,
|
||||
,,,,,# ## ## #,,,,,
|
||||
|
@ -23,7 +23,7 @@
|
|||
#. ## P ## .#
|
||||
### ## ## ######## ## ## ###
|
||||
### ## ## ######## ## ## ###
|
||||
# ## ## ## #
|
||||
# ## .##. ## #
|
||||
# ########## ## ########## #
|
||||
# ########## ## ########## #
|
||||
# #
|
||||
|
|
|
@ -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.
BIN
bin/Brick.class
BIN
bin/Brick.class
Binary file not shown.
BIN
bin/Game.class
BIN
bin/Game.class
Binary file not shown.
BIN
bin/Ghost.class
BIN
bin/Ghost.class
Binary file not shown.
BIN
bin/Lives.class
BIN
bin/Lives.class
Binary file not shown.
BIN
bin/Main.class
BIN
bin/Main.class
Binary file not shown.
BIN
bin/Map.class
BIN
bin/Map.class
Binary file not shown.
Binary file not shown.
BIN
bin/Player.class
BIN
bin/Player.class
Binary file not shown.
BIN
bin/Point.class
BIN
bin/Point.class
Binary file not shown.
212
src/Game.java
212
src/Game.java
|
@ -133,12 +133,36 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delay(30);
|
||||
lastT = System.nanoTime(); // delta time
|
||||
|
||||
|
||||
frame.setVisible(true);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
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++;
|
||||
if (ghosts[0].feared == true) {
|
||||
if (Ghost.fearedTimer != 0) {
|
||||
|
@ -159,102 +183,103 @@ public class Game {
|
|||
player.setLocation(player.getPos('x', dt), player.getPos('y', dt));
|
||||
|
||||
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;
|
||||
ghost_possible[i][1] = false;
|
||||
ghost_possible[i][2] = false;
|
||||
ghost_possible[i][3] = false;
|
||||
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][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];
|
||||
}
|
||||
}
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
for (int i = 0; i < 35; i++) { // 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)
|
||||
if (ghosts[0].feared) {
|
||||
|
||||
ghosts[i].setPos('x', Map.ghost_posX[i]);
|
||||
ghosts[i].setPos('y', Map.ghost_posY[i]);
|
||||
ghosts[i].setIsDead(true);
|
||||
ghosts[i].setDeathTimer(1000);
|
||||
ghosts[i].setPos('x', -100);
|
||||
ghosts[i].setPos('y', -100);
|
||||
score += 1000;
|
||||
System.out.println("Geist"+ i + " ist gestorben" + ghosts[i].getIsDead());
|
||||
|
||||
} else {
|
||||
player.lives--;
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@ public class Ghost extends Picture { // Die
|
|||
public boolean left;
|
||||
public boolean right;
|
||||
|
||||
public boolean feared = false;
|
||||
public boolean feared;
|
||||
public static int fearedTimer;
|
||||
private int deathTimer;
|
||||
private boolean isDead;
|
||||
private double HCost;
|
||||
private int type;
|
||||
|
||||
|
@ -36,7 +38,7 @@ public class Ghost extends Picture { // Die
|
|||
} else if (type == 1) {
|
||||
this.changeSauce("Pinky");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
if (coordinate == 'x') { // Auslesen der 'x' - Koordinate:
|
||||
|
|
Loading…
Reference in New Issue