From 5c4d039a308965b34eb7f238280d91da75ac4642 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Jun 2020 19:54:41 +0200 Subject: [PATCH] pathfinding_complete --- assets/Map.txt | 53 ++++++------------ bin/.gitignore | 1 - bin/Brick.class | Bin 450 -> 450 bytes bin/Game.class | Bin 4499 -> 5697 bytes bin/Ghost.class | Bin 1453 -> 1479 bytes bin/Main.class | Bin 558 -> 558 bytes bin/Map.class | Bin 1968 -> 1968 bytes bin/Picture.class | Bin 1415 -> 1415 bytes bin/Player.class | Bin 3510 -> 3510 bytes src/Game.java | 137 +++++++++++++++++++++++++++++++++++++--------- src/Ghost.java | 67 ++++++++++++++--------- 11 files changed, 169 insertions(+), 89 deletions(-) delete mode 100644 bin/.gitignore diff --git a/assets/Map.txt b/assets/Map.txt index 89bbe50..f9a47bf 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -1,36 +1,17 @@ -############################# ##### -# # # # 0 # -# # ############### ######### ##### -# # # ## ### ##### -# # # ########## ### ########## -# # # ################# ##### ##### -# # # # # #### #### -# # # # #################### ###### -# # # # # P####### ###### -# # # # # ################## ###### -# # # # # # ######## ###### -# # # # # # ####### ## ## -# # # # # # ############# ###### ## -# # # # # ############# ## ## -# # # # ################### # ## ## -# # ################# ## -#######################123######### -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# -# -Es werden nur die ersten 35 Zeilen und Zeichen dieses Dokuments benutzt. \ No newline at end of file +################################### +# # +# ############ ###### ########### # +# ###### # +# ############ ###### ########### # +# ############ ########### # +# ## ### # +# ############ 0123 ########### # +# ########## ###### ######### # +# # # P # # # +# ############ # ## # ########### # +# # ## # # +# ############ ## ########### # +# ############# ############ # +# ############# #### ############ # +# # +################################### \ No newline at end of file diff --git a/bin/.gitignore b/bin/.gitignore deleted file mode 100644 index 7cf58ac..0000000 --- a/bin/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/assets/ diff --git a/bin/Brick.class b/bin/Brick.class index 50ef0edbf9e3ab3e130be745f874a171441c4509..98f1c69aeacb64cc67c5adfd0911ce8b54b732c9 100644 GIT binary patch delta 17 ZcmX@ae2AIj)W2Q(7#J8#HgfD@1OPz1273Si delta 17 ZcmX@ae2AIj)W2Q(7#J8VH*)M^1OPzQ27mwn diff --git a/bin/Game.class b/bin/Game.class index d9d8a4df2bf9b35f39498ac94969571c9b2f5019..3f67209902b612ee495bb967ca0e421ab6f5581f 100644 GIT binary patch literal 5697 zcma)A33yc175?wcd-Ep41BQ@@)_@>dl7NXuTw{O`WHS&X0SlqZka-D%lbJY~0CA}s zSU23YEN&<^MQIUCCMb$KR$N+_D&hw2;@aBJiXikq@4X}wO{@7b_nv#sJg3!WHVKfx0E3BBez^X|q=(Pz_6|%~Owz#lyQH0dV z;{{txaziL)MSnt`CRmbv4bf1ul~C}PPqQJx)yBlRLmP2&981`6m!Tf*^0m63C;-*g+zQs`sbT^_FqB_r_| z$=wm0q18uXG3uCDMjNQKnsR-oL}HQTC@RR!o5?9<@vs$u7lTdYU|a8ew990~MG!*ny5V@hco^phzL}r)~}47z`F6$C=RK zGjPI>r`hfe;CN@+$tDc=4V=Qo*bWumQ6_r9G%$v1sji-FU@TYX#2|oDhw)Ss83>4+ z2__~&{2B^}X?(67?84BZWMNsnz9Am7V#(sXo{(beX(q}sg&rpJX;yQ2q%mp5BvOZ^ z$*~qvMqwJcIB%vfSD2WF(-n+HD=C5G8geI1a%hz%s)W{yw2nv$&rB0%fFTVKKQq!8 znHMFSmODFdrXRB@YFen~s41bCOr2xmw>Xoz#;H}2q)g0qt+La+GMQjLySB_V5fZs3 zCr`H;Bj<)FS)|mM2!pH#lQ7Pz4K+oRWzl$}RncH2?EDh-uF-WS<|9IHaBf*VMpq;y zTnYoyydi{8gidlbpKT(FdNS4hi0Po*Zf@`33LuVi3~(4+F78zJb?e_L}q8^PWOe{t-<1x0pwCpq%hxGW9Tr7!mo{95u zfkJO88yl)QyDkxLiZO-yrztFp%WMg0F)oyiM4uMpViT9(QYi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3Z=s5RWX?0e)c|(%nJpvOHk>u5-pfgJ|(~#kx_NkcWsgu)rX4sR* z44(yNzpzi^dA(M=@CPnde}z#imR_O!67$v6k<6+p%UAUyOx224nEggT0$2IG#&O^{ z9YxYzY68{mZr6B|`on@K!#`*>X zCfQW377mY)sr`=S<7#0Xh1Ril%y*HL688tLP|5;FU&RFymq@qB>Z0@Cs=-od@O*Ob!tV#zr<%`<^(=L2t@3Hcs>J`4|{xpj_ud%_BwNe=Wztnk+#?L3%;;Sur`;jeK bp1=lgZd36^AKco+@ilDY0T~5a3bXST?t#&8 diff --git a/bin/Main.class b/bin/Main.class index 1a833566a526260096197e0752201ee1225efe0a..ef3f06657c480cca5388e7e157aa4fac9de8cadb 100644 GIT binary patch delta 17 ZcmZ3-vW|u0)W2Q(7#J8#Hgc#j0RTNS1;PLT delta 17 ZcmZ3-vW|u0)W2Q(7#J8VH*%;k0RTNr1;+pY diff --git a/bin/Map.class b/bin/Map.class index bba024803145b8b86e7fdc8432ce5ca91f14b54e..791a8616b38cce62af49d017cf6043e3931971e0 100644 GIT binary patch delta 17 ZcmdnMzk#3Q)W2Q(7#J8#Hgc?B2LM0D24esK delta 17 ZcmdnMzk#3Q)W2Q(7#J8VH*&0C2LM0c250~P diff --git a/bin/Picture.class b/bin/Picture.class index f720bca0ebe0c6c5649446ce9cce8fd8400937c9..3737254b48ab4d6c68bbddd077d0d3181feadfaa 100644 GIT binary patch delta 17 YcmZqYZs+DW^>5cc1_lO`jU4r?06E$P-T(jq delta 17 YcmZqYZs+DW^>5cc1_lPpjU4r?06Fso;{X5v diff --git a/bin/Player.class b/bin/Player.class index f9425e24af9d9a0dc5be19e37b6ee1494e181cd2..ccedcbfca8e3e4cde8d0dc4c9773bd6b461fb1e9 100644 GIT binary patch delta 17 Zcmdlcy-k|q)W2Q(7#J8#Hgc@v1pq<-29p2) delta 17 Zcmdlcy-k|q)W2Q(7#J8VH*&1w1pq=B2ABW< diff --git a/src/Game.java b/src/Game.java index 2fdf780..8b1b633 100644 --- a/src/Game.java +++ b/src/Game.java @@ -1,8 +1,12 @@ import java.awt.Color; +import java.util.*; + import javax.swing.JFrame; import javax.swing.JPanel; +import java.lang.Math; + // In dieser Klasse findet der größte Teil des Spiels statt: // Rendern von Map, Geistern, Pac-Man etc. // Überprüfung von Kollisionen verschiedener Elemente (der komplizierteste Teil des Programms) @@ -20,7 +24,7 @@ public class Game { private long dt; private long lastT; - private int delaytimer = 9; + private int delaytimer = 10; @SuppressWarnings("unused") private long fps = 60; @@ -34,6 +38,9 @@ public class Game { // nach rechts --> x wird größer // nach unten --> y wird größer + int minn; + int[] HCost = new int[4]; + public Game() { // Erstellen des Konstruktors (Was soll passieren, sobald dieses Klasse // aufgerufen wird?) @@ -41,12 +48,9 @@ public class Game { panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert - ghosts = new Ghost[1]; // 4 Geister + ghosts = new Ghost[4]; // 4 Geister - boolean[] ghost_up_possible = new boolean[ghosts.length]; - boolean[] ghost_down_possible = new boolean[ghosts.length]; - boolean[] ghost_left_possible = new boolean[ghosts.length]; - boolean[] ghost_right_possible = new boolean[ghosts.length]; + boolean[][] ghost_possible = new boolean[ghosts.length][4]; player = new Player(); // Pac-Man @@ -104,38 +108,110 @@ public class Game { player.setLocation(player.getPos('x', dt), player.getPos('y', dt)); // Aktualiesieren der Positionen der Geister: - for (int i = 0; i < ghosts.length; i++) { - ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); - } + //for (int i = 0; i < ghosts.length; i++) { + // ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); + //} for (int i = 0; i < ghosts.length; i++) { + + ghost_possible[i][0] = false; + ghost_possible[i][1] = false; + 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 ){ + ghost_possible[i][0] = true; - if (Map.bricks[((ghosts[i].getPos('y', 0) - 10) / 20) - 1][(ghosts[i].getPos('x', 0) - 10) - / 20] == null) { - ghost_up_possible[i] = true; } - if (Map.bricks[((ghosts[i].getPos('y', 0) - 10) / 20) + 1][(ghosts[i].getPos('x', 0) - 10) - / 20] == null) { - ghost_down_possible[i] = 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 ){ + ghost_possible[i][1] = true; + } - if (Map.bricks[(ghosts[i].getPos('y', 0) - 10) / 20][((ghosts[i].getPos('x', 0) - 10) / 20) - - 1] == null) { - ghost_left_possible[i] = 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 ){ + ghost_possible[i][2] = true; } - if (Map.bricks[(ghosts[i].getPos('y', 0) - 10) / 20][((ghosts[i].getPos('x', 0) - 10) / 20) - + 1] == null) { - ghost_right_possible[i] = 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 ){ + ghost_possible[i][3] = true; } - ghost_up_possible[i] = false; - ghost_down_possible[i] = false; - ghost_left_possible[i] = false; - ghost_right_possible[i] = false; + 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); + HCost[2] = ghosts[i].getHCost(player, 0, -1); + HCost[3] = ghosts[i].getHCost(player, 0, 1); + // + int minn = 10000; + + if (ghosts[i].up == true) { + HCost[3] = 10000; + } + if (ghosts[i].down == true) { + HCost[2] = 10000; + } + if (ghosts[i].left == true) { + HCost[0] = 10000; + } + if (ghosts[i].right == true) { + HCost[1] = 10000; + } + + + for (int j = 0; j < 4; j++) { + if (ghost_possible[i][j] == false) { + HCost[j] = 10500; + } + } + for (int j = 0; j < 4; j++) { + if (minn > HCost[j]) { + minn = HCost[j]; + } + } + + //System.out.println(minn); + + // + for (int j = 0; j < 4; j++) { + if (HCost[j] == minn) { + if (j == 0) { + ghosts[i].right = true; + ghosts[i].left = false; + ghosts[i].down = false; + ghosts[i].up = false; + break; + } + if (j == 1) { + ghosts[i].left = true; + ghosts[i].right = false; + ghosts[i].down = false; + ghosts[i].up = false; + break; + } + if (j == 2) { + ghosts[i].up = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].down = false; + break; + } + if (j == 3) { + ghosts[i].down = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].up = false; + break; + } + } + } + + } - System.out.println(ghosts[0].getHCost(player)); + // Kollision von Pac-Man mit Bricks: for (int i = 0; i < 35; i++) { // für jeden Brick for (int j = 0; j < 35; j++) { // für jeden Brick @@ -170,6 +246,7 @@ public class Game { player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll for (int i = 0; i < ghosts.length; i++) { + ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); if (player.getPos('x', 0) < ghosts[i].getPos('x', 0) + 20 && player.getPos('x', 0) > ghosts[i].getPos('x', 0) - 20 && player.getPos('y', 0) < ghosts[i].getPos('y', 0) + 20 @@ -198,4 +275,10 @@ public class Game { e.printStackTrace(); } } + private int conv(float a) { //90.0 --> 4 + int b = (int) (a - 10 )/ 20; + return b; + } + + } diff --git a/src/Ghost.java b/src/Ghost.java index 0dad550..cc3a483 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -4,9 +4,16 @@ public class Ghost extends Picture { // Die private static final long serialVersionUID = -5352006665147359473L; - private int xPos; - private int yPos; + public int xPos; + public int yPos; + + public boolean up; + public boolean down; + public boolean left; + public boolean right; + + //private float speed = 0.00000007f; private int HCost; public Ghost(int index) { @@ -25,14 +32,7 @@ public class Ghost extends Picture { // Die } - public int getPos(char coordinate, long dt) { - if (coordinate == 'x') { - return xPos; - } else if (coordinate == 'y') { - return yPos; - } else - return -1; - } + public void setPos(char coordinate, int newPos) { if (coordinate == 'x') { @@ -42,28 +42,45 @@ public class Ghost extends Picture { // Die } } - public void moveUp() { - } - public void moveDown() { - + /* + public void setDirection(String dir) { + direction = dir; } - - public void moveRight() { - + public String getDirection() { + return direction; } - - public void moveLeft() { + */ + public int getHCost(Player player, int mod_x, int mod_y) { - } - - public int getHCost(Player player) { - - HCost = (int) Math.sqrt(Math.pow(xPos - player.getPos('x', 0), 2) + Math.pow(yPos - player.getPos('y', 0), 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)); 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 -= speed * dt; + xPos -= 1; + } else if (right && dt != 0) { + // xPos += speed * dt; + xPos += 1; + } + return (int) xPos; + } else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate: + if (down && dt != 0) { + // yPos += speed * dt; + yPos += 1; + } else if (up && dt != 0) { + // yPos -= speed * dt; + yPos -= 1; + } + return (int) yPos; //(int) + } else { + return -1; + } + } }