From f7ed737e2376d836fa0bc95c105dc152a6f316ee Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 7 Jun 2020 13:47:17 +0200 Subject: [PATCH] win-condition + ghost killen + feared --- assets/Map.txt | 2 +- assets/feared.png | Bin 0 -> 505 bytes bin/Game.class | Bin 7249 -> 7952 bytes bin/Ghost.class | Bin 1937 -> 2130 bytes src/Game.java | 116 +++++++++++++++++++++++++++++++++++----------- src/Ghost.java | 19 ++++++-- 6 files changed, 104 insertions(+), 33 deletions(-) create mode 100644 assets/feared.png diff --git a/assets/Map.txt b/assets/Map.txt index 3e47a5e..7e17f76 100644 --- a/assets/Map.txt +++ b/assets/Map.txt @@ -27,4 +27,4 @@ # ########## ## ########## # # ########## ## ########## # # # -############################ \ No newline at end of file +############################ diff --git a/assets/feared.png b/assets/feared.png new file mode 100644 index 0000000000000000000000000000000000000000..c68d520bd83f827d3bd62c84068fce830e610372 GIT binary patch literal 505 zcmVPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!~g&e!~vBn4jTXf0gg#TK~y+Tt&_h> z13?hRzlcacB_ITAqX8r7wD3JNFJLP^K)@n}HWpT5X)UOgwvtxRUJ(B@3Mu4B6!kpx z#+%)pbF;Sx2l|7}&du$8^X=@WL`3*c3JESXkXdwfjgkq6@Cveke8BO{mP%)M*vty& zI`p|>Z1F;ZB9!OK#T8Y8vPIWbWlhghH9a#d;6p@HhrV7Nt(YKqMXNh$9)6krGC{&c z$B43^jKz5(89r8z^`Iaiy1ONcBBG~9T0cy`!Kf*adzyP^&p7Dz@lmayS+DA3nCz}L zi};(++rWD0p}2wej_@2rMku zDivg0hcJr%x5AM&~84W{GP*lcpvJ&BQ1f)Gfc6A7cwMilo*VfqgioPW>aGPEC`` zCctJvs8_Hp5zM8*rWplwjZK7@vBjk|Sj1-Z@8Ixa7EX8rDjlrhUx<;0V#ugN1ERYI9E{a@q z8?$MspkW9S3|1`*HaAK0;ewLzAY&EfH5JpU8)O08gq@TsXaq(Q?4`@Nf*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&CQ#Z^i*P3e7HEIqeQw61}mWC6FaKbj)3)n{YK&)Y0 zb>a%EYR_d{!+VTa+UPtLPB=zT`*;w?4JSCumSgc|6eA~N91{|(MSX)hgvQ3gV`UQE6d;*?0iY7k^t_D-$tn1mO&AP3Mx_KEsw79W= zMJMhMa6(yEW!yz85mrkK$|CKaj8{aOga5AvLxb}(<`NnI-VE9@tFFb z7Z<{5)>wI0H@aYlgOQVw1ul9Np1vexH!a~z%Lb+;Gt;s)twr3>v|J`y8!Ow_CqAUwewv`v?Z?dm`#Hqn3bU5AKM+pV8N>vLeLqezF8t z)j`}Qbn>F7=yjnR0kNtWpcg|g!p!QZbwh-w;xi~#oLt_Z?}ha*mRp>VB%s;D<2P}> zPSjwb5F{AzZ3;%gtwTij;SKnzf|3Yh$CNrK8ra-{KFV~KboxmqWK!s@;k=*_#9Mfq zU5Jf~Bx5nj*kJKC@pK56Y7C^`D87xlFGRjW_YUSGv{C;%tNzPcaBF42x9NV0cYU6$ zudT4P`nU}v&v2b7v06&ENU5HXl6i*7&kvE@#~%XNwud|ai=0}1Y4EQExP1>-{|)Y+ zJ&~&aX5;vn-hF|<`M>R`YdmBBy?kC&m{03=faRMFCxXRfrpERmz?Mz~i-~qIK8`&)upFy6#Ge_E zy@UJ%80AY4$5q_G1ST Map.bigpoints[j][i].xPos - 6 + && player.getPos('y', 0) < Map.bigpoints[j][i].yPos + 6 + && player.getPos('y', 0) > Map.bigpoints[j][i].yPos - 6) { + + Map.bigpoints[j][i].setBounds(0, 0, 0, 0); + + Map.bigpoints[j][i] = null; + + score += 1000; + scoreLabel.setText(Integer.toString(score)); + for (i = 0; i < 4; i++) { + ghosts[i].feared = true; + Ghost.fearedTimer = 1000; } + } } } @@ -300,19 +330,25 @@ public class Game { 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 - && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) { + && player.getPos('y', 0) > ghosts[i].getPos('y', 0) - 20) + if (ghosts[0].feared) { - player.lives--; + ghosts[i].setPos('x', Map.ghost_posX[i]); + ghosts[i].setPos('y', Map.ghost_posY[i]); + score += 1000; + } else { + player.lives--; - liveLabels[player.lives].setBounds(0, 0, 0, 0); - if (player.lives == 0) { - System.exit(0); - } - - delay(200); - for (int j = 0; j < ghosts.length; j++) { - ghosts[j].setPos('x', Map.ghost_posX[j]); - ghosts[j].setPos('y', Map.ghost_posY[j]); + liveLabels[player.lives].setBounds(0, 0, 0, 0); + if (player.lives == 0) { + System.exit(0); + } + + delay(200); + for (int j = 0; j < ghosts.length; j++) { + ghosts[j].setPos('x', Map.ghost_posX[j]); + ghosts[j].setPos('y', Map.ghost_posY[j]); + } player.setPos('x', Map.pac_posX); player.setPos('y', Map.pac_posY); player.up = false; @@ -320,18 +356,42 @@ public class Game { player.right = false; player.left = false; } + } + + + fps = 1000000000 / dt; + // System.out.println("fps: " + fps); + + 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; + } } } - fps = 1000000000 / dt; - - // System.out.println("fps: " + fps); - - delay(delaytimer); // Ein delay zum Ende der Hauptschleife - + 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); + } + } } } + + // Methode zum verzögern (warten) in ms public void delay(int time) { diff --git a/src/Ghost.java b/src/Ghost.java index 5769201..ae3485e 100644 --- a/src/Ghost.java +++ b/src/Ghost.java @@ -11,8 +11,10 @@ public class Ghost extends Picture { // Die public boolean down; public boolean left; public boolean right; - - private int HCost; + + public boolean feared = false; + public static int fearedTimer; + private double HCost; private int type; public Ghost(int type) { @@ -40,6 +42,7 @@ public class Ghost extends Picture { // Die } public int getHCost(Player player, int mod_x, int mod_y) { + if (!feared) { if (type == 0) { HCost = (int) Math.sqrt(Math.pow((((xPos - 10) / 20) + mod_x) - ((player.getPos('x', 0) - 10) / 20), 2) @@ -54,9 +57,17 @@ public class Ghost extends Picture { // Die 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)); } - return HCost; + + } + 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; + + } - public int getPos(char coordinate, long dt) { // Hier kommt die zuvor erwähnte delta time ins Spiel if (coordinate == 'x') { // Auslesen der 'x' - Koordinate: