From 76bb2891150be577b2a451ec450cf7cb96a032d9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 7 Jun 2020 14:09:46 +0200 Subject: [PATCH] =?UTF-8?q?change=20sauce=20und=20geister=20ki=20ver=C3=A4?= =?UTF-8?q?ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/.gitignore | 7 +++++ bin/Game.class | Bin 8345 -> 8746 bytes bin/Ghost.class | Bin 2130 -> 2254 bytes src/Game.java | 73 ++++++++++++++++++++++++++++--------------- src/Ghost.java | 80 ++++++++++++++++++++++++++---------------------- src/Lives.java | 3 ++ 6 files changed, 101 insertions(+), 62 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index 0ffe84e..0007eb6 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,3 +1,10 @@ /BigPoint.class +/Brick.class +/Game.class +/Ghost.class /Lives.class +/Main.class +/Map.class +/Picture.class +/Player.class /Point.class diff --git a/bin/Game.class b/bin/Game.class index f1da680de55949e7dde19ab78aa461f21cb30efc..1fe4910395ba8c716e03a4b6e24202932b29d736 100644 GIT binary patch delta 3926 zcma)9YjjlA75={aoVjyv2$@V0Adp}nKzL~oh=x}Hc?$$0FF^=oNWegV1SGX(Q1L+# z1g`?26+v{RMT!!V5u^)r*`gp-YkgF0K~XA2EeZ=oQRq1{lb59~f82Zb{?6X}JLl|k z_C2R6Z|6|!=;h}R0=S;@_gHg1Aqx}mgN@6`Ak4DjiG@q&1ic_(qXptEOo8jg1gbXP zrABa=B^nKzCOw2Ur)=Re@##FQ%SdTu*?5bZmbV$u^3vsN8z30i!e%^M5}x8<#fTwg z6h-s3+!XF zZ}YaPlJEwbH^MJEQ#x;1u-wAu>}Rt-o)iNNE}vH+=X0RVK@!l5f~AF(GS*<5L!^^u zQQ@2jiv(}7+i+M@bgC{giQFwm;o&GZ-P&nP<*g>Cxo=p3*3&sdL@X~21{cW`jp{PV z;!GBroaJ7zGB|s0hR;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z^&_*M|yLC0k}^X=P?ol z@1bKu#!=0lR&W7%0q>l7hdQK(hI)r&?nMP3qCkxrpIE#!Uz+QZ{6`A5Vw-R90eK93 z1_TCny9HQ!&LJugTBl6FS+jC$p=FyA;JSjCysev<2;vrzhqYNhD;>IhF++OJAgROjqwv1q7EcgD0PSHezl--;jBWCjN~Myq z1<5LPcMV5Y5KYFKl9miJ8??4jO<)gc?WKPEs70EjREI*hi}R8~3di{)VntFuNirUX zj1Qh@gsc5{-(}#LC6bR9@=Sey+o!L0R zY3t+E9AcjxMv3+&J%c^>07vkc_D3AW&ure`*r>nLzQA!2#tG4flVY6q22P0yoDpAO zK&;X}=8sLbx$1VxdXI@`xQvfwkI}p0^qBOn((^jqwgvv@(4OPQbDVYFMJDqf>9(He zBph20OHT8T@G#dNp{u*?;Ujc@ha17UMa0xAR7|NlQ_;hW$wx>!8CzQ!?QX^-Go-lp zR-Mt2V3ke5G73{OE0AE-O~EpFwIknZyD>+(|{gS9-k{TFV@m>U29 diff --git a/src/Game.java b/src/Game.java index 5f43905..f0eff60 100644 --- a/src/Game.java +++ b/src/Game.java @@ -53,7 +53,6 @@ public class Game { ImageIcon img = new ImageIcon("assets/Pacman_Right.png"); frame.setIconImage(img.getImage()); - panel = new JPanel(); // darauf werden alle sichtbaren Elemente gespeichert ghosts = new Ghost[4]; // 4 Geister @@ -147,6 +146,7 @@ public class Game { } else { for (int i = 0; i < ghosts.length; i++) { ghosts[i].feared = false; + ghosts[i].ogSauce(); } } } @@ -320,6 +320,32 @@ public class Game { for (i = 0; i < 4; i++) { ghosts[i].feared = true; Ghost.fearedTimer = 1000; + ghosts[i].changeSauce("feared"); + if (ghosts[i].left) { + ghosts[i].right = true; + ghosts[i].left = false; + ghosts[i].down = false; + ghosts[i].up = false; + + } else if (ghosts[i].right) { + ghosts[i].left = true; + ghosts[i].right = false; + ghosts[i].down = false; + ghosts[i].up = false; + + } else if (ghosts[i].down) { + ghosts[i].up = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].down = false; + + } else if (ghosts[i].up) { + ghosts[i].down = true; + ghosts[i].right = false; + ghosts[i].left = false; + ghosts[i].up = false; + + } } } @@ -361,41 +387,38 @@ public class Game { player.left = false; } } - - - fps = 1000000000 / dt; - // System.out.println("fps: " + fps); + fps = 1000000000 / dt; - delay(delaytimer); // Ein delay zum Ende der Hauptschleife + // System.out.println("fps: " + fps); - if (frames % 100 == 0) { - boolean empty = true; - for (int i = 0; i < 35; i++) { - for (int j = 0; j < 35; j++) { - if (Map.points[j][i] != null) { - empty = false; + delay(delaytimer); // Ein delay zum Ende der Hauptschleife + + if (frames % 100 == 0) { + boolean empty = true; + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + if (Map.points[j][i] != null) { + empty = false; + } } } - } - for (int i = 0; i < 35; i++) { - for (int j = 0; j < 35; j++) { - if (Map.bigpoints[j][i] != null) { - empty = false; + for (int i = 0; i < 35; i++) { + for (int j = 0; j < 35; j++) { + if (Map.bigpoints[j][i] != null) { + empty = false; + } } } + if (empty) { + scoreLabel.setText("YOU WON"); + delay(1000); + System.exit(0); + } } - if (empty) { - scoreLabel.setText("YOU WON"); - delay(1000); - System.exit(0); - } - } } } - - // Methode zum verzögern (warten) in ms public void delay(int time) { diff --git a/src/Ghost.java b/src/Ghost.java index ae3485e..ba1af44 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -11,26 +11,32 @@ public class Ghost extends Picture { // Die public boolean down; public boolean left; public boolean right; - + public boolean feared = false; public static int fearedTimer; private double HCost; private int type; + public Ghost(int type) { - - + super("Pinky"); // Aufrufen der übergeordneten Klasse this.type = type; // xPos = 150 + 40 * index; + this.ogSauce(); + } + + public void ogSauce() { if (type == 0) { this.changeSauce("Blinky"); } else if (type == 2) { this.changeSauce("Inky"); } else if (type == 3) { this.changeSauce("Clyde"); + } else if (type == 1) { + this.changeSauce("Pinky"); } - + } public void setPos(char coordinate, int newPos) { @@ -43,53 +49,53 @@ public class Ghost extends Picture { // Die public int getHCost(Player player, int mod_x, int mod_y) { if (!feared) { - if (type == 0) { + if (type == 0) { - 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)); - } else if (type == 1) { - HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2) - + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2)); - } else if (type == 2) { - HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((300 - 10 + 80) / 20), 2) - + Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2)); - } else if (type == 3) { - 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) + 100 - 10) / 20), 2)); - } - - } - else { - HCost = 10 * (1 / (Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 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)); + } else if (type == 1) { + HCost = (int) Math + .sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10 + 80) / 20), 2) + + Math.pow((((yPos - 10) / 20) + mod_y) - ((player.getPos('y', 0) - 10) / 20), 2)); + } else if (type == 2) { + HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((300 - 10 + 80) / 20), 2) + + Math.pow((((yPos - 10) / 20) + mod_y) - ((100 - 10) / 20), 2)); + } else if (type == 3) { + 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) + 100 - 10) / 20), 2)); + } + + } else { + HCost = 10 * (1 / (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 (int) HCost; - - + + return (int) 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 && Game.frames % 4 == 0) { - - xPos -= 1; - + + xPos -= 1; + } else if (right && dt != 0 && Game.frames % 4 == 0) { - - xPos += 1; - + + xPos += 1; + } return (int) xPos; } else if (coordinate == 'y') { // Auslesen der 'y' - Koordinate: if (down && dt != 0 && Game.frames % 4 == 0) { - - yPos += 1; - + + yPos += 1; + } else if (up && dt != 0 && Game.frames % 4 == 0) { - - yPos -= 1; - + + yPos -= 1; + } return (int) yPos; // (int) } else { diff --git a/src/Lives.java b/src/Lives.java index 48f99f6..f3be98a 100644 --- a/src/Lives.java +++ b/src/Lives.java @@ -1,6 +1,9 @@ public class Lives extends Picture{ + + private static final long serialVersionUID = -4715442447789971450L; + public Lives() { super("heart"); }