Essentieller Bugfix: Richtung wurde vor Blockkollision berechnet
parent
580eff56ad
commit
2ac42aaa10
|
@ -1,7 +1 @@
|
||||||
/Brick.class
|
/assets/
|
||||||
/Game.class
|
|
||||||
/Ghost.class
|
|
||||||
/Main.class
|
|
||||||
/Map.class
|
|
||||||
/Picture.class
|
|
||||||
/Player.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.
|
@ -98,7 +98,7 @@ public class Game {
|
||||||
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt));
|
||||||
}
|
}
|
||||||
|
|
||||||
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -110,15 +110,19 @@ public class Game {
|
||||||
&& player.getPos('y', 0) > Map.bricks[j][i].yPos - 20) {
|
&& player.getPos('y', 0) > Map.bricks[j][i].yPos - 20) {
|
||||||
if (player.left) {
|
if (player.left) {
|
||||||
player.setPos('x', Map.bricks[j][i].xPos + 20);
|
player.setPos('x', Map.bricks[j][i].xPos + 20);
|
||||||
|
player.setPos('y', Map.bricks[j][i].yPos);
|
||||||
player.left = false;
|
player.left = false;
|
||||||
} else if (player.right) {
|
} else if (player.right) {
|
||||||
player.setPos('x', Map.bricks[j][i].xPos - 20);
|
player.setPos('x', Map.bricks[j][i].xPos - 20);
|
||||||
|
player.setPos('y', Map.bricks[j][i].yPos);
|
||||||
player.right = false;
|
player.right = false;
|
||||||
} else if (player.up) {
|
} else if (player.up) {
|
||||||
player.setPos('y', Map.bricks[j][i].yPos + 20);
|
player.setPos('y', Map.bricks[j][i].yPos + 20);
|
||||||
|
player.setPos('x', Map.bricks[j][i].xPos);
|
||||||
player.up = false;
|
player.up = false;
|
||||||
} else if (player.down) {
|
} else if (player.down) {
|
||||||
player.setPos('y', Map.bricks[j][i].yPos - 20);
|
player.setPos('y', Map.bricks[j][i].yPos - 20);
|
||||||
|
player.setPos('x', Map.bricks[j][i].xPos);
|
||||||
player.down = false;
|
player.down = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +131,8 @@ public class Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
|
||||||
|
|
||||||
for (int i = 0; i < ghosts.length; i++) {
|
for (int i = 0; i < ghosts.length; i++) {
|
||||||
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 20
|
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 20
|
||||||
&& player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 20
|
&& player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 20
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
|
||||||
|
|
||||||
if (keyCode == 37 || pressed_left && System.currentTimeMillis() - timer <= blob) {
|
if (keyCode == 37 || pressed_left && System.currentTimeMillis() - timer <= blob) {
|
||||||
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 Bick
|
for (int j = 0; j < 35; j++) { // für jeden Brick
|
||||||
if (Map.bricks[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks
|
if (Map.bricks[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks
|
||||||
if (Map.bricks[j][i].xPos + 20 == (int) xPos && (int) yPos < Map.bricks[j][i].yPos + 20
|
if (Map.bricks[j][i].xPos + 20 == (int) xPos && (int) yPos < Map.bricks[j][i].yPos + 20
|
||||||
&& (int) yPos > Map.bricks[j][i].yPos - 20) { // wenn Pac-Man gerade rechts an einem
|
&& (int) yPos > Map.bricks[j][i].yPos - 20) { // wenn Pac-Man gerade rechts an einem
|
||||||
|
|
Loading…
Reference in New Issue