Geister langsamer
parent
4ee6c9b8d4
commit
be5b9617b5
|
@ -1,2 +1,9 @@
|
|||
/Point.class
|
||||
/Brick.class
|
||||
/Game.class
|
||||
/Ghost.class
|
||||
/Lives.class
|
||||
/Main.class
|
||||
/Map.class
|
||||
/Picture.class
|
||||
/Player.class
|
||||
/Point.class
|
||||
|
|
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/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.
|
@ -28,7 +28,7 @@ public class Game {
|
|||
|
||||
private JLabel liveLabels[];
|
||||
|
||||
private int delaytimer = 12;
|
||||
private int delaytimer = 4;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private long fps = 60;
|
||||
|
@ -41,7 +41,7 @@ public class Game {
|
|||
// oben links (0|0)
|
||||
// nach rechts --> x wird größer
|
||||
// nach unten --> y wird größer
|
||||
|
||||
public static int frames;
|
||||
int minn;
|
||||
int[] HCost = new int[4];
|
||||
|
||||
|
@ -125,6 +125,7 @@ public class Game {
|
|||
lastT = System.nanoTime(); // delta time
|
||||
|
||||
while (true) { // Hauptschleife
|
||||
frames ++;
|
||||
|
||||
dt = System.nanoTime() - lastT; // delta time
|
||||
lastT = System.nanoTime(); // delta time
|
||||
|
@ -195,7 +196,8 @@ public class Game {
|
|||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if ((frames % 2) != 0) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (HCost[j] == minn) {
|
||||
if (j == 0) {
|
||||
ghosts[i].right = true;
|
||||
|
@ -224,10 +226,10 @@ public class Game {
|
|||
ghosts[i].left = false;
|
||||
ghosts[i].up = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Kollision von Pac-Man mit Bricks:
|
||||
|
@ -297,7 +299,7 @@ public class Game {
|
|||
if (player.lives == 0) {
|
||||
System.exit(0);
|
||||
}
|
||||
System.out.println(player.lives);
|
||||
|
||||
delay(200);
|
||||
for (int j = 0; j < ghosts.length; j++) {
|
||||
ghosts[j].setPos('x', Map.ghost_posX[j]);
|
||||
|
|
|
@ -13,18 +13,19 @@ public class Ghost extends Picture { // Die
|
|||
public boolean right;
|
||||
|
||||
private int HCost;
|
||||
private int type;
|
||||
public Ghost(int type) {
|
||||
|
||||
public Ghost(int index) {
|
||||
|
||||
super("Pinky"); // Aufrufen der übergeordneten Klasse
|
||||
|
||||
this.type = type;
|
||||
// xPos = 150 + 40 * index;
|
||||
|
||||
if (index == 0) {
|
||||
if (type == 0) {
|
||||
this.changeSauce("Blinky");
|
||||
} else if (index == 2) {
|
||||
} else if (type == 2) {
|
||||
this.changeSauce("Inky");
|
||||
} else if (index == 3) {
|
||||
} else if (type == 3) {
|
||||
this.changeSauce("Clyde");
|
||||
}
|
||||
|
||||
|
@ -39,27 +40,45 @@ public class Ghost extends Picture { // Die
|
|||
}
|
||||
|
||||
public int getHCost(Player player, int mod_x, int mod_y) {
|
||||
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));
|
||||
|
||||
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));
|
||||
}
|
||||
return 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) {
|
||||
xPos -= 1;
|
||||
} else if (right && dt != 0) {
|
||||
xPos += 1;
|
||||
if (left && dt != 0 && (Game.frames % 3) == 0) {
|
||||
|
||||
xPos -= 1;
|
||||
|
||||
} else if (right && dt != 0 && (Game.frames % 3) == 0) {
|
||||
|
||||
xPos += 1;
|
||||
|
||||
}
|
||||
return (int) xPos;
|
||||
} else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate:
|
||||
if (down && dt != 0) {
|
||||
yPos += 1;
|
||||
} else if (up && dt != 0) {
|
||||
yPos -= 1;
|
||||
if (down && dt != 0 && (Game.frames % 3) == 0) {
|
||||
|
||||
yPos += 1;
|
||||
|
||||
} else if (up && dt != 0 && (Game.frames % 3) == 0) {
|
||||
|
||||
yPos -= 1;
|
||||
|
||||
}
|
||||
return (int) yPos; // (int)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue