aalles mögliche ll

master
Lenz Wiechers 2020-06-08 18:49:02 +02:00
parent 39445beb84
commit 8f45f0cba3
33 changed files with 126 additions and 115 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 359 B

BIN
assets/Geister/Blinky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

BIN
assets/Geister/Clyde.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 B

BIN
assets/Geister/Inky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

BIN
assets/Geister/Pinky.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

BIN
assets/Geister/feared.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 413 B

19
assets/Maps/TestMap.txt Normal file
View File

@ -0,0 +1,19 @@
#########
#L0123,,#
#########
#########
##############
#,,,,,. #
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,P,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,#
#,,,,,,,,,,,,R
##############

View File

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 242 B

View File

Before

Width:  |  Height:  |  Size: 257 B

After

Width:  |  Height:  |  Size: 257 B

View File

Before

Width:  |  Height:  |  Size: 227 B

After

Width:  |  Height:  |  Size: 227 B

View File

Before

Width:  |  Height:  |  Size: 246 B

After

Width:  |  Height:  |  Size: 246 B

View File

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

View File

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

View File

Before

Width:  |  Height:  |  Size: 250 B

After

Width:  |  Height:  |  Size: 250 B

View File

Before

Width:  |  Height:  |  Size: 226 B

After

Width:  |  Height:  |  Size: 226 B

View File

Before

Width:  |  Height:  |  Size: 243 B

After

Width:  |  Height:  |  Size: 243 B

View File

Before

Width:  |  Height:  |  Size: 257 B

After

Width:  |  Height:  |  Size: 257 B

View File

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 776 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

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

@ -29,7 +29,7 @@ public class Game {
private JLabel fpsLabel; private JLabel fpsLabel;
private JLabel liveLabels[]; private JLabel liveLabels[];
private int delaytimer = 4; private long delaytimer = 4000;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private long fps = 60; private long fps = 60;
@ -46,6 +46,8 @@ public class Game {
int minn; int minn;
int[] HCost = new int[4]; int[] HCost = new int[4];
boolean empty; // Für die Überprüfung, ob alle points weg sind, benötigt
public Game(String selectedMap) { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse public Game(String selectedMap) { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse
// aufgerufen wird?) // aufgerufen wird?)
@ -65,7 +67,7 @@ public class Game {
for (int i = 0; i < liveLabels.length; i++) { for (int i = 0; i < liveLabels.length; i++) {
liveLabels[i] = new Lives(); liveLabels[i] = new Lives();
panel.add(liveLabels[i]); panel.add(liveLabels[i]);
liveLabels[i].setBounds(710 + 20 * i, 35 , 20, 20); liveLabels[i].setBounds(710 + 20 * i, 35, 20, 20);
} }
scoreLabel = new JLabel(Integer.toString(score)); scoreLabel = new JLabel(Integer.toString(score));
@ -80,7 +82,7 @@ public class Game {
fpsLabel.setForeground(Color.WHITE); fpsLabel.setForeground(Color.WHITE);
fpsLabel.setBounds(710, 45, 500, 50); fpsLabel.setBounds(710, 45, 500, 50);
fpsLabel.setFont(f); fpsLabel.setFont(new Font("Consolas", Font.BOLD, 15));
panel.add(player); // Pac-Man wird dem Panel hinzugefügt panel.add(player); // Pac-Man wird dem Panel hinzugefügt
frame.addKeyListener(player); // KeyListener wird hinzugefügt, man kann nun Pac-Maan mit der tastatur steuern frame.addKeyListener(player); // KeyListener wird hinzugefügt, man kann nun Pac-Maan mit der tastatur steuern
@ -112,31 +114,22 @@ public class Game {
player.setBounds(player.getPos('x', 0), player.getPos('y', 0), 20, 20); // Pac-Man wird das erste Mal gerendert player.setBounds(player.getPos('x', 0), player.getPos('y', 0), 20, 20); // Pac-Man wird das erste Mal gerendert
for (int i = 0; i < 35; i++) { // für jeden Brick for (int i = 0; i < 35; i++) { // für die ganze Map
for (int j = 0; j < 35; j++) { // für jeden Brick for (int j = 0; j < 35; j++) { // für die ganze Map
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
panel.add(Map.bricks[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt panel.add(Map.bricks[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt
Map.bricks[j][i].setBounds(Map.bricks[j][i].xPos, Map.bricks[j][i].yPos, 20, 20); // Rendern des // Rendern des Bricks:
Map.bricks[j][i].setBounds(Map.bricks[j][i].xPos, Map.bricks[j][i].yPos, 20, 20);
} }
}
}
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
// Analog für die points und die BigPoints:
if (Map.bigpoints[j][i] != null) {
panel.add(Map.bigpoints[j][i]);
Map.bigpoints[j][i].setBounds(Map.bigpoints[j][i].xPos, Map.bigpoints[j][i].yPos, 20, 20);
} }
} if (Map.points[j][i] != null) {
} panel.add(Map.points[j][i]);
for (int i = 0; i < 35; i++) { // für jeden Brick // points Map.points[j][i].setBounds(Map.points[j][i].xPos, Map.points[j][i].yPos, 20, 20);
for (int j = 0; j < 35; j++) { // für jeden Brick
if (Map.bigpoints[j][i] != null) { // Damit kein Fehler auftritt wegen nicht vorhandenen Bricks
panel.add(Map.bigpoints[j][i]); // Der jeweilige Brick wird zum panel hinzugefügt
Map.bigpoints[j][i].setBounds(Map.bigpoints[j][i].xPos, Map.bigpoints[j][i].yPos, 20, 20); // Rendern
// des
} }
} }
} }
@ -152,19 +145,16 @@ public class Game {
delay(1000); delay(1000);
frame.setVisible(true); frame.setVisible(true);
// ----------------------------------------------------------------------------------------------------------------------------------------------------- while (true) { // Main-Loop
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------------------------------------------
while (true) { // Hauptschleife dt = System.nanoTime() - lastT; // delta time
lastT = System.nanoTime(); // delta time
player.setLocation(player.getPos('x', dt), player.getPos('y', dt));
if (ghosts[0].feared == true) { if (ghosts[0].feared == true) {
if (Ghost.fearedTimer != 0) { if (Ghost.fearedTimer != 0) {
Ghost.fearedTimer--; Ghost.fearedTimer--;
} else { } else {
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
ghosts[i].feared = false; ghosts[i].feared = false;
@ -173,10 +163,6 @@ public class Game {
} }
} }
} }
dt = System.nanoTime() - lastT; // delta time
lastT = System.nanoTime(); // delta time
player.setLocation(player.getPos('x', dt), player.getPos('y', dt));
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
if (!ghosts[i].getIsDead()) { if (!ghosts[i].getIsDead()) {
@ -341,7 +327,7 @@ public class Game {
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
ghosts[i].feared = true; ghosts[i].feared = true;
Ghost.fearedTimer = 1000; Ghost.fearedTimer = 1000;
ghosts[i].changeSauce("feared"); ghosts[i].changeSauce("Geister/feared");
if (ghosts[i].left) { if (ghosts[i].left) {
ghosts[i].dire = 0; ghosts[i].dire = 0;
} else if (ghosts[i].right) { } else if (ghosts[i].right) {
@ -363,38 +349,32 @@ public class Game {
} }
} }
if (Map.Left != null) { // Kollision von Pac-Man mit den Portalen:
if (Map.Left != null && Map.Right != null) {
if (player.getPos('x', 0) < Map.Left.xPos + 20 && player.getPos('x', 0) > Map.Left.xPos - 20 if (player.getPos('x', 0) < Map.Left.xPos + 20 && player.getPos('x', 0) > Map.Left.xPos - 20
&& player.getPos('y', 0) < Map.Left.yPos + 20 && player.getPos('y', 0) > Map.Left.yPos - 20) { && player.getPos('y', 0) < Map.Left.yPos + 20 && player.getPos('y', 0) > Map.Left.yPos - 20
&& Map.Right != null) {
player.xPos = Map.Right.xPos - 20;
player.yPos = Map.Right.yPos;
if (Map.Right != null) { } else if (player.getPos('x', 0) < Map.Right.xPos + 20 && player.getPos('x', 0) > Map.Right.xPos - 20
player.xPos = Map.Right.xPos - 20; && player.getPos('y', 0) < Map.Right.yPos + 20 && player.getPos('y', 0) > Map.Right.yPos - 20
player.yPos = Map.Right.yPos; && Map.Left != null) {
player.xPos = Map.Left.xPos + 20;
player.yPos = Map.Left.yPos;
}
} }
} }
if (Map.Right != null) {
if (player.getPos('x', 0) < Map.Right.xPos + 20 && player.getPos('x', 0) > Map.Right.xPos - 20
&& player.getPos('y', 0) < Map.Right.yPos + 20 && player.getPos('y', 0) > Map.Right.yPos - 20) {
if (Map.Left != null) {
player.xPos = Map.Left.xPos + 20;
player.yPos = Map.Left.yPos;
}
}
}
// Geister LOOP // Geister LOOP
for (int i = 0; i < ghosts.length; i++) { for (int i = 0; i < ghosts.length; i++) {
//
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); // Setzen der Positionen
// der Geister
if (ghosts[i].getIsDead()) { if (ghosts[i].getIsDead()) {
if (ghosts[i].getDeathTimer() != 0) { if (ghosts[i].getDeathTimer() != 0) {
ghosts[i].setDeathTimer(ghosts[i].getDeathTimer() - 1); ghosts[i].setDeathTimer(ghosts[i].getDeathTimer() - 1);
} else { } else {
ghosts[i].setIsDead(false); ghosts[i].setIsDead(false);
ghosts[i].setPos('x', Map.ghost_posX[i]); ghosts[i].setPos('x', Map.ghost_posX[i]);
@ -403,31 +383,38 @@ public class Game {
} }
} }
ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); // Kollision der Geister mit Pac-Man:
if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18 if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 18
&& player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 18 && player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 18
&& player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 14 && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 14
&& player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 14) && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 14)
if (ghosts[0].feared) { if (ghosts[i].feared) {
ghosts[i].setIsDead(true); ghosts[i].setIsDead(true);
ghosts[i].setDeathTimer(1000); ghosts[i].setDeathTimer(1500);
ghosts[i].setPos('x', -100); ghosts[i].setPos('x', -100);
ghosts[i].setPos('y', -100); ghosts[i].setPos('y', -100);
score += 1000; score += 1000;
scoreLabel.setText(Integer.toString(score));
} else { } else {
player.lives--; player.lives--;
liveLabels[player.lives].setBounds(0, 0, 0, 0); liveLabels[player.lives].setBounds(0, 0, 0, 0); // Das herz wird "entfernt"
if (player.lives == 0) {
System.exit(0); if (player.lives == 0) { // Wenn der Spieler keine Leben mehr übrig hat
System.exit(0); // Das Programm wird beendet
} }
delay(200); delay(200); // Damit nicht sofort wieder alle losgeht
// Die Positionen der Geister werden zurückgesetzt
for (int j = 0; j < ghosts.length; j++) { for (int j = 0; j < ghosts.length; j++) {
ghosts[j].setPos('x', Map.ghost_posX[j]); ghosts[j].setPos('x', Map.ghost_posX[j]);
ghosts[j].setPos('y', Map.ghost_posY[j]); ghosts[j].setPos('y', Map.ghost_posY[j]);
} }
// Die Position von Pac-Man wird zurückgesetzt, und er bewegt sich nicht mehr.
player.setPos('x', Map.pac_posX); player.setPos('x', Map.pac_posX);
player.setPos('y', Map.pac_posY); player.setPos('y', Map.pac_posY);
player.up = false; player.up = false;
@ -436,15 +423,10 @@ public class Game {
player.left = false; player.left = false;
} }
// Geister LOOP } // Ende vom Geister Loop
}
//
if (frames % 100 == 0) { // Das folgende soll nur alle 100 frames überprüft werden:
// Ein delay zum Ende der Hauptschleife empty = true;
if (frames % 100 == 0) {
boolean empty = true;
for (int i = 0; i < 35; i++) { for (int i = 0; i < 35; i++) {
for (int j = 0; j < 35; j++) { for (int j = 0; j < 35; j++) {
if (Map.points[j][i] != null) { if (Map.points[j][i] != null) {
@ -460,27 +442,39 @@ public class Game {
} }
} }
if (empty) { if (empty) {
scoreLabel.setText("YOU WON"); fpsLabel.setText("YOU WON");
delay(1000); delay(5000);
System.exit(0); // HIER DEN HIGHSCORE IMPLEMENTIEREN System.exit(0); // Das Programm wird beendet
// HIER DEN HIGHSCORE IMPLEMENTIEREN
} }
} }
player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll
fps = 1000000000 / dt;
fpsLabel.setText("fps: " + Integer.toString((int) fps)); fpsLabel.setText("fps: " + Integer.toString((int) fps)); // Refreshen vom fpsLabel
frames++; // FRAMES WIRD HOCHGESETZT frames++; // FRAMES WIRD HOCHGESETZT
delay(delaytimer);
// if (frames % 15 == 0) {
fps = 1000000000 / dt; // Berechnen der fps
if (frames > 100) {
if (fps > 200) {
delaytimer += 100;
} else if (fps < 180) {
delaytimer -= 100;
}
}
}
delay(delaytimer); // delay ist wichtig, um die geschwindigkeit der objekte und die fps zu
// kontrollieren
} }
// ENDE DER WHILE-SCHLEIFE // ENDE DES MAIN-LOOPS
} }
// Methode zum verzögern (warten) in ms // Methode zum verzögern (warten) in ms
public void delay(int time) { public void delay(long time) {
try { try {
Thread.sleep(time); Thread.sleep(0, (int) time);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -24,7 +24,7 @@ public class Ghost extends Picture { // Die
public Ghost(int type) { public Ghost(int type) {
super("Pinky"); // Aufrufen der übergeordneten Klasse super("Geister/Pinky"); // Aufrufen der übergeordneten Klasse
this.type = type; this.type = type;
// xPos = 150 + 40 * index; // xPos = 150 + 40 * index;
@ -33,13 +33,13 @@ public class Ghost extends Picture { // Die
public void ogSauce() { public void ogSauce() {
if (type == 0) { if (type == 0) {
this.changeSauce("Blinky"); this.changeSauce("Geister/Blinky");
} else if (type == 2) { } else if (type == 2) {
this.changeSauce("Inky"); this.changeSauce("Geister/Inky");
} else if (type == 3) { } else if (type == 3) {
this.changeSauce("Clyde"); this.changeSauce("Geister/Clyde");
} else if (type == 1) { } else if (type == 1) {
this.changeSauce("Pinky"); this.changeSauce("Geister/Pinky");
} }
} }

View File

@ -41,7 +41,7 @@ public class Player extends Picture implements KeyListener { // extends Picture
public Player() { // Erstellen des Konstruktors public Player() { // Erstellen des Konstruktors
super("Pacman_Right"); // Aufrufen der übergeordneten Klasse (Picture) super("Pac-Man/Pacman_Right"); // Aufrufen der übergeordneten Klasse (Picture)
} }
@ -79,8 +79,6 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_up = false; pressed_up = false;
pressed_down = false; pressed_down = false;
} else { // ansonsten: } else { // ansonsten:
// soll Pac-Man sich sobald er kann nach links bewegen // soll Pac-Man sich sobald er kann nach links bewegen
@ -118,9 +116,6 @@ public class Player extends Picture implements KeyListener { // extends Picture
pressed_up = false; pressed_up = false;
pressed_down = false; pressed_down = false;
} else { } else {
pressed_left = false; pressed_left = false;
pressed_right = true; pressed_right = true;
@ -259,49 +254,52 @@ public class Player extends Picture implements KeyListener { // extends Picture
if (Dir == "Left") { if (Dir == "Left") {
if (aniFrames == 1 || aniFrames == 5) { if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Left1"); this.changeSauce("Pac-Man/Pacman_Left1");
} else if (aniFrames == 2 || aniFrames == 4) { } else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Left"); this.changeSauce("Pac-Man/Pacman_Left");
} else if (aniFrames == 3) { } else if (aniFrames == 3) {
this.changeSauce("Pacman_Left3"); this.changeSauce("Pac-Man/Pacman_Left3");
} }
}if (Dir == "Right") { }
if (Dir == "Right") {
if (aniFrames == 1 || aniFrames == 5) { if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Right1"); this.changeSauce("Pac-Man/Pacman_Right1");
} else if (aniFrames == 2 || aniFrames == 4) { } else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Right"); this.changeSauce("Pac-Man/Pacman_Right");
} else if (aniFrames == 3) { } else if (aniFrames == 3) {
this.changeSauce("Pacman_Right3"); this.changeSauce("Pac-Man/Pacman_Right3");
} }
}if (Dir == "Up") { }
if (Dir == "Up") {
if (aniFrames == 1 || aniFrames == 5) { if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Up1"); this.changeSauce("Pac-Man/Pacman_Up1");
} else if (aniFrames == 2 || aniFrames == 4) { } else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Up"); this.changeSauce("Pac-Man/Pacman_Up");
} else if (aniFrames == 3) { } else if (aniFrames == 3) {
this.changeSauce("Pacman_Up3"); this.changeSauce("Pac-Man/Pacman_Up3");
} }
}if (Dir == "Down") { }
if (Dir == "Down") {
if (aniFrames == 1 || aniFrames == 5) { if (aniFrames == 1 || aniFrames == 5) {
this.changeSauce("Pacman_Down1"); this.changeSauce("Pac-Man/Pacman_Down1");
} else if (aniFrames == 2 || aniFrames == 4) { } else if (aniFrames == 2 || aniFrames == 4) {
this.changeSauce("Pacman_Down"); this.changeSauce("Pac-Man/Pacman_Down");
} else if (aniFrames == 3) { } else if (aniFrames == 3) {
this.changeSauce("Pacman_Down3"); this.changeSauce("Pac-Man/Pacman_Down3");
} }