From b43fb65fb35bdbcce03ba5467e0eb40428946db1 Mon Sep 17 00:00:00 2001 From: Lenz Date: Thu, 21 May 2020 16:12:32 +0200 Subject: [PATCH] =?UTF-8?q?Berechnung=20in=20welche=20Richtung=20die=20Gei?= =?UTF-8?q?ster=20sich=20bewegen=20k=C3=B6nnen=20hinzugef=C3=BCgt=20(Begin?= =?UTF-8?q?n=20vom=20Pathfinding)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Map.txt | 8 ++++---- bin/Game.class | Bin 3819 -> 4774 bytes bin/Ghost.class | Bin 884 -> 1297 bytes src/Game.java | 50 ++++++++++++++++++++++++++++++++++++++++-------- src/Ghost.java | 25 ++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 12 deletions(-) diff --git a/assets/Map.txt b/assets/Map.txt index a873f86..7851a67 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -1,8 +1,8 @@ -###############################0### -# # ## -# # ############### ############### +############################# ##### +# # # # 0 # +# # ############### ######### ##### # # # ## ### ##### -# # # ########## ### ##### ##### +# # # ########## ### ########## # # # ################# ##### ##### # # # # #### #### # # # # #################### ###### diff --git a/bin/Game.class b/bin/Game.class index 79eeb982993effaefe03c7aeb8861a3971a36e62..9cea366349fbc1bfd1f4aaecd2da00b47d3b01af 100644 GIT binary patch delta 2716 zcmai$3vg8B6~}+yee7;_7TrQJ*3vSWTAc*3&=@k97^r}40I@}4Xs`lHb|r~xvdsfX zRqkL@vDjAQDmG%V(7?8|6v1Rs9%;30P@u6s`cV29q%TUyO;N>%iFhW0!g;yLXx+7sIRMTlRzg!%w9*{?&qz%r>? z7m3%+o!Zc%vyO-O4HJYW-mp5>s{8w0h@Y~|meo=5z!8EdUJ7wC+2)($d|*|5b8Fl3 z_Qdi;b8BnE%6Lr5UAI&*!3*e8IiZYKPn6@$_j297bKI&yrfyV>Tih0@yK!M8Q5_L} zKc|Ac&OiP9LoqG<_O`3*TVj!Dh=1{hbl)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ioMDtJg?P7*<#nFl^XWNo LsI%vS>U#1Y@))iC delta 554 zcmYk3KTpC?6vfYL0ZUsdmcLR&P^eH;)WsM#HxmaF6DJo!h=NFrQKO4|24r($V_`Az zPvYPQ@Uys>IIE|WsA+QZ?tSOn-+5_Q{S2sYUoWo!Hn7%J54tyrgDC<3ZlisCtwKgb zM+i}YSaGLWy{uMR)%Ia!@BFOMKHMzrD~JmOwpyNAAgN>8Rco~)>gs#di&|ZQCE(lU zJ_R$~j}vV{hYBqSfl{v_)_d-SEi10278!;@ho24S|L6Ai!$Cf-= zHD;LSc@pwBJ<xh diff --git a/src/Game.java b/src/Game.java index 3238259..9b3a999 100644 --- a/src/Game.java +++ b/src/Game.java @@ -19,9 +19,9 @@ public class Game { // Delta time: siehe https://en.wikipedia.org/wiki/Delta_timing private long dt; private long lastT; - + private int delaytimer = 9; - + @SuppressWarnings("unused") private long fps = 60; @@ -41,7 +41,12 @@ public class Game { panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert - ghosts = new Ghost[4]; // 4 Geister + ghosts = new Ghost[1]; // 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]; player = new Player(); // Pac-Man @@ -103,7 +108,36 @@ public class Game { ghosts[i].setLocation(ghosts[i].getPos('x', dt), ghosts[i].getPos('y', dt)); } - + for (int i = 0; i < ghosts.length; i++) { + + 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[(ghosts[i].getPos('y', 0) - 10) / 20][((ghosts[i].getPos('x', 0) - 10) / 20) + - 1] == null) { + ghost_left_possible[i] = 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; + } + + System.out.println("up: " + ghost_up_possible[i] + " | down: " + ghost_down_possible[i] + " | left: " + + ghost_left_possible[i] + " | right: " + ghost_right_possible[i]); + + // System.out.println((ghosts[i].getPos('y', 0) - 10) / 20); + + ghost_up_possible[i] = false; + ghost_down_possible[i] = false; + ghost_left_possible[i] = false; + ghost_right_possible[i] = false; + + } // Kollision von Pac-Man mit Bricks: for (int i = 0; i < 35; i++) { // für jeden Brick @@ -135,7 +169,7 @@ public class Game { } } } - + player.calcDir(0); // Berechnen wo Pac-Man als nächstes hin soll for (int i = 0; i < ghosts.length; i++) { @@ -150,11 +184,11 @@ public class Game { } } fps = 1000000000 / dt; - + // System.out.println("fps: " + fps + " | delaytimer: " + delaytimer); - + delay(delaytimer); // Ein delay zum Ende der Hauptschleife - + } } diff --git a/src/Ghost.java b/src/Ghost.java index 69b0050..8d2b66b 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -6,6 +6,10 @@ public class Ghost extends Picture { // Die private int xPos; private int yPos; + + private int HCost; + private int GCost; + private int FCost; public Ghost(int index) { @@ -39,5 +43,26 @@ public class Ghost extends Picture { // Die yPos = newPos; } } + + public void moveUp() { + } + + public void moveDown() { + + } + + public void moveRight() { + + } + + public void moveLeft() { + + } + + public int getHCost() { + + + return HCost; + } }