mit points aber buggy
parent
7b4a54d1b5
commit
c3cdb120c6
|
@ -1,17 +1,17 @@
|
|||
###################################
|
||||
# #
|
||||
# ############ ###### ########### #
|
||||
# ###### #
|
||||
# ############ ###### ########### #
|
||||
# ############ ########### #
|
||||
# ## ### #
|
||||
# ############ 0123 ########### #
|
||||
# ########## ###### ######### #
|
||||
# # # P # # #
|
||||
# ##### ###### ###### ###### #### #
|
||||
# ###### #
|
||||
# ##### ###### ###### ###### #### #
|
||||
# ##### ###### ###### #### #
|
||||
# ##,### #
|
||||
# ##### ###### ,0123, ###### #### #
|
||||
# ### ###### ###### ###### ## #
|
||||
# # # P # # #
|
||||
# ##### ###### # ## # ###### #### #
|
||||
# # ## # #
|
||||
# ############ ## ########### #
|
||||
# ############# ############ #
|
||||
# ############# #### ############ #
|
||||
# ### ######## ## ######## ## #
|
||||
# ##### ####### ####### #### #
|
||||
# ##### ####### #### ####### #### #
|
||||
# #
|
||||
###################################
|
Binary file not shown.
After Width: | Height: | Size: 149 B |
|
@ -0,0 +1 @@
|
|||
/Point.class
|
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/Map.class
BIN
bin/Map.class
Binary file not shown.
BIN
bin/Player.class
BIN
bin/Player.class
Binary file not shown.
|
@ -93,7 +93,15 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 35; i++) { // für jeden Brick // points
|
||||
for (int j = 0; j < 35; j++) { // für jeden Brick
|
||||
if (Map.points[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks
|
||||
panel.add(Map.points[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt
|
||||
Map.points[j][i].setBounds(Map.points[j][i].xPos, Map.points[j][i].yPos, 20, 20); // Rendern des
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
frame.setVisible(true);
|
||||
|
||||
lastT = System.nanoTime(); // delta time
|
||||
|
@ -119,25 +127,31 @@ public class Game {
|
|||
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 ){
|
||||
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 ){
|
||||
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 ){
|
||||
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 ){
|
||||
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;
|
||||
}
|
||||
|
||||
System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " + HCost[3]);
|
||||
|
||||
|
||||
|
||||
// System.out.println(HCost[0] + " " + HCost[1] + " " + HCost[2] + " " +
|
||||
// HCost[3]);
|
||||
|
||||
HCost[0] = ghosts[i].getHCost(player, 1, 0);
|
||||
HCost[1] = ghosts[i].getHCost(player, -1, 0);
|
||||
|
@ -159,7 +173,6 @@ public class Game {
|
|||
HCost[1] = 10000;
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (ghost_possible[i][j] == false) {
|
||||
HCost[j] = 10500;
|
||||
|
@ -208,7 +221,6 @@ public class Game {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -242,6 +254,12 @@ public class Game {
|
|||
}
|
||||
}
|
||||
}
|
||||
if ((player.getPos('x', 0) - 10) % 20 == 0 && (player.getPos('y', 0) - 10) % 20 == 0 && Map.points[conv(player.getPos('y', 0))][conv(player.getPos('x', 0))] != null) {
|
||||
Map.points[conv(player.yPos)][conv(player.xPos)].setBounds(0, 0, 0, 0);
|
||||
|
||||
System.out.println("" + conv(player.yPos) + " " + conv(player.xPos));
|
||||
}
|
||||
|
||||
|
||||
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
||||
|
||||
|
@ -275,10 +293,10 @@ public class Game {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private int conv(float a) { // 90.0 --> 4
|
||||
int b = (int) (a - 10) / 20;
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.io.FileReader;
|
|||
public class Map {
|
||||
|
||||
public static Brick bricks[][] = new Brick[35][35]; // Zweidimensionales Array für alle Bricks
|
||||
public static Point points[][] = new Point[35][35];
|
||||
// Zweidimensionale Arrays siehe
|
||||
// https://de.wikipedia.org/wiki/Feld_(Datentyp)#Mehrdimensional_/_in-sich-mehrdimensional
|
||||
|
||||
|
@ -51,6 +52,8 @@ public class Map {
|
|||
} else if (line.charAt(j) == '3') {
|
||||
ghosts[3].setPos('x', 10 + 20 * j);
|
||||
ghosts[3].setPos('y', 10 + 20 * i);
|
||||
} else if (line.charAt(j) == ' ') {
|
||||
points[i][j] = new Point(10 + 20 * j, 10 + 20 * i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ public class Player extends Picture implements KeyListener { // extends Picture
|
|||
|
||||
private static final long serialVersionUID = -4225811153447791553L;
|
||||
|
||||
private float xPos; // Position auf dem Frame in x-Richtung
|
||||
private float yPos; // Position auf dem Frame in y-Richtung
|
||||
public float xPos; // Position auf dem Frame in x-Richtung
|
||||
public float yPos; // Position auf dem Frame in y-Richtung
|
||||
|
||||
public int lives = 3;
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// Diese Klasse stellt die einzelnen Bicks (Wände) auf der Map dar.
|
||||
|
||||
public class Point extends Picture { // Die übergeordnete Klasse ist Picture
|
||||
|
||||
|
||||
|
||||
private static final long serialVersionUID = -1204077187616807301L;
|
||||
|
||||
|
||||
public int xPos; // Position auf dem Frame in x-Richtung
|
||||
public int yPos; // Position auf dem Frame in y-Richtung
|
||||
|
||||
public Point(int newXPos, int newYPos) { // Erstellen des Konstruktors mit den Koordinaten, an denen sich der Brick
|
||||
// beefinden soll.
|
||||
|
||||
super("point"); // Aufrufen der übergeordneten Klasse
|
||||
|
||||
// Setzen der Positionen:
|
||||
xPos = newXPos;
|
||||
yPos = newYPos;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue