Essentieller Bugfix: Richtung wurde vor Blockkollision berechnet

master
Lenz Wiechers 2020-05-10 14:25:46 +02:00
parent 580eff56ad
commit 2ac42aaa10
10 changed files with 9 additions and 9 deletions

8
bin/.gitignore vendored
View File

@ -1,7 +1 @@
/Brick.class
/Game.class
/Ghost.class
/Main.class
/Map.class
/Picture.class
/Player.class
/assets/

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

@ -98,7 +98,7 @@ public class Game {
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:
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) {
if (player.left) {
player.setPos('x', Map.bricks[j][i].xPos + 20);
player.setPos('y', Map.bricks[j][i].yPos);
player.left = false;
} else if (player.right) {
player.setPos('x', Map.bricks[j][i].xPos - 20);
player.setPos('y', Map.bricks[j][i].yPos);
player.right = false;
} else if (player.up) {
player.setPos('y', Map.bricks[j][i].yPos + 20);
player.setPos('x', Map.bricks[j][i].xPos);
player.up = false;
} else if (player.down) {
player.setPos('y', Map.bricks[j][i].yPos - 20);
player.setPos('x', Map.bricks[j][i].xPos);
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++) {
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 20
&& player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 20

View File

@ -53,7 +53,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
if (keyCode == 37 || pressed_left && System.currentTimeMillis() - timer <= blob) {
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].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