From 9cef59819693fc186be498dfc7b4a051ce9b5805 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 15 Sep 2026 11:33:47 +0200 Subject: [PATCH] PowerUps/JumpBoost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit neue Klassen: PowerUps, JumpBoostItem Die aktivieren und das deaktivieren der PowerUps wird im Player durchgeführt. --- SMIMS-Game/JumpBoostItem.class | Bin 0 -> 742 bytes SMIMS-Game/JumpBoostItem.ctxt | 8 +++ SMIMS-Game/JumpBoostItem.java | 21 +++++++ SMIMS-Game/Player.class | Bin 2024 -> 2752 bytes SMIMS-Game/Player.ctxt | 6 +- SMIMS-Game/Player.java | 29 +++++++++- SMIMS-Game/PlayerTestWorld.class | Bin 574 -> 669 bytes SMIMS-Game/PlayerTestWorld.java | 3 + SMIMS-Game/PowerUps.class | Bin 0 -> 984 bytes SMIMS-Game/PowerUps.ctxt | 10 ++++ SMIMS-Game/PowerUps.java | 28 +++++++++ SMIMS-Game/images/mushroom.png | Bin 0 -> 1693 bytes SMIMS-Game/project.greenfoot | 94 ++++++++++++++++++++++++++----- 13 files changed, 183 insertions(+), 16 deletions(-) create mode 100644 SMIMS-Game/JumpBoostItem.class create mode 100644 SMIMS-Game/JumpBoostItem.ctxt create mode 100644 SMIMS-Game/JumpBoostItem.java create mode 100644 SMIMS-Game/PowerUps.class create mode 100644 SMIMS-Game/PowerUps.ctxt create mode 100644 SMIMS-Game/PowerUps.java create mode 100644 SMIMS-Game/images/mushroom.png diff --git a/SMIMS-Game/JumpBoostItem.class b/SMIMS-Game/JumpBoostItem.class new file mode 100644 index 0000000000000000000000000000000000000000..8ce3e47627e22629d32abfef2f85617399c3cb8c GIT binary patch literal 742 zcmZ9KOK;Oa6ot>^Q75UJq-h%-INDn)?o^4yh*3CqbN%BK+7r9#%b(n6@>y~(4e+yqLuMlI!gU>IX=2P z3A{@g8`vbd*k`&e6WiDk=uV^_gj&Xl^tB2n??xBg(8a#xUU+k_A9&%Ue;jy8;`EA> zRI8xxszf{MxQ6QnZkV`G9yzg` zOEs6vme8a%xMJp1$298nh60u2Xe?Q*t3vrUosMLD=8XcLblk}If}t0yEM6W~^tobX zEqC>5)0Mt=o?t@HKXz>t_7zsRHah@^CI8}Rr zjsF2n0$Nu9)g=J1R)7yQmOZv>ciIbd%HPl};V0Vef&Cdq=hgyu{$iUH107Chi$mVd V(cL0_iEh(z4|eYAfZ7rc{{VAejSv6; literal 0 HcmV?d00001 diff --git a/SMIMS-Game/JumpBoostItem.ctxt b/SMIMS-Game/JumpBoostItem.ctxt new file mode 100644 index 0000000..ce278d8 --- /dev/null +++ b/SMIMS-Game/JumpBoostItem.ctxt @@ -0,0 +1,8 @@ +#BlueJ class context +comment0.target=JumpBoostItem +comment0.text=\r\n\ Write\ a\ description\ of\ class\ JumpBoostItem\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n +comment1.params= +comment1.target=void\ act() +comment2.params= +comment2.target=void\ collect() +numComments=3 diff --git a/SMIMS-Game/JumpBoostItem.java b/SMIMS-Game/JumpBoostItem.java new file mode 100644 index 0000000..dc588f3 --- /dev/null +++ b/SMIMS-Game/JumpBoostItem.java @@ -0,0 +1,21 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class JumpBoostItem here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class JumpBoostItem extends PowerUps +{ + int duration = 60*5; + public void act() + { + touchedByPlayer(); + } + + @Override void collect(){ + Player player = getIntersectingObjects(Player.class).get(0); + player.reveivePowerUp(duration, "JumpBoost"); + } +} diff --git a/SMIMS-Game/Player.class b/SMIMS-Game/Player.class index 4e8541392580c88817adc53b3868f4103af34e4e..5090825a78a5c4ba0988fabf9e206a895f69b9b3 100644 GIT binary patch literal 2752 zcmZuyTXR!Y6#hdAvCqLp@>jTkJO5270X2^5(=ROT8c%G9&&cm11CA*H_f#Vf5X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H59+tk+Ml?rwo!dhPwLfs&&hlI}GhYu~ZwuWiow*OkZXGuCW%bV}Tiyukm5}N>6L?$khjm jRk`{Q9})Kk^=*j$gRLB{2)2{S{c+B{-#O>fAUjeDJYPd}*mmvUhK6uvV6F{uw8fAx&<=yTX~%jlcqmd^ z6QZm^%gYl740KAhvASMen+bg3R)Q6&=rWL!ideC~nmP%bZCIx2=yr%@qmgB^cp#>`e6X#+$Z(tA?G#uPxWPFDknzn0q#q%-m z8BM1%g;i_A$~u-?$ueBqt>gxjGZzhffJ?Mj5y1oHV_sUlY~aHk@q!dwHSiIxX=tyB zpx~9PK!p^^A@uYt3_Q6;<)G-Ws7xE0)hw!oTGOfmbE8=afg^73vf&&>vSk;}mTGXy|J3 zx{+s6KI5(XC2@z8v*;SGT#y{$Br_0VXNYj*6Xz-<-?Ezdbk)q~s%Ab;&QY)~)o5|| znCCUlC(PH-%w%*MF*Dh{jSf@aM$!y#A-L19ylbn#owSuQ>o_vc;TZoX`9HIV-b3GjZjNc%=pptYbg`}MA*Y(iA=x*G zC!=_VutFY6z5fOSo9H%)nl-l&D|0ba$CcE_?BOTZmB&)U%2qG!_iUoe=SuEFLiLX7iR94}Ch|rqb$2fo@b8GQ&h?d;;?a%EIn(%lvgtdPG@SuhL diff --git a/SMIMS-Game/Player.ctxt b/SMIMS-Game/Player.ctxt index 2806518..5208ed6 100644 --- a/SMIMS-Game/Player.ctxt +++ b/SMIMS-Game/Player.ctxt @@ -11,4 +11,8 @@ comment4.params= comment4.target=void\ fall() comment5.params= comment5.target=boolean\ collision() -numComments=6 +comment6.params= +comment6.target=void\ handlePowerUps() +comment7.params=duration\ type +comment7.target=void\ reveivePowerUp(int,\ java.lang.String) +numComments=8 diff --git a/SMIMS-Game/Player.java b/SMIMS-Game/Player.java index 10df53f..2abc718 100644 --- a/SMIMS-Game/Player.java +++ b/SMIMS-Game/Player.java @@ -8,8 +8,13 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) */ public class Player extends Actor { + int jumpBoostDuration = -1; + int jumpBoostStrength = 5; + + private int speed = 6; - private int jumpStrength = 20; + private int currentJumpStrength; + private int defaultJumpStrength = 15; private int gravity = 1; private int verticalSpeed = 0; @@ -21,6 +26,7 @@ public class Player extends Actor moveLeftAndRight(); jump(); fall(); + handlePowerUps(); } // Bewegung nach links und rechts @@ -42,7 +48,7 @@ public class Player extends Actor { if (Greenfoot.isKeyDown("space") && onGround) { - verticalSpeed = -jumpStrength; + verticalSpeed = -currentJumpStrength; onGround = false; } } @@ -101,4 +107,23 @@ public class Player extends Actor return false; } } + + public void handlePowerUps(){ + if (jumpBoostDuration >= 0){ + jumpBoostDuration -= 1; + } else if (jumpBoostDuration <= -1){ + currentJumpStrength = defaultJumpStrength; + } + } + + public void reveivePowerUp(int duration, String type){ + switch(type){ + case "dummy": + break; + case "JumpBoost": + currentJumpStrength = defaultJumpStrength; + currentJumpStrength += jumpBoostStrength; + jumpBoostDuration = duration; + } + } } diff --git a/SMIMS-Game/PlayerTestWorld.class b/SMIMS-Game/PlayerTestWorld.class index 99be99adc32fd8c1bb24f698083891ffd1526545..cb40e72d0f2d0c4789fcdb8a8af47b3c58b51dfd 100644 GIT binary patch delta 269 zcmdnTGMAO>)W2Q(7#J8F88jwxZ4+Z>kYr@w^(xIRaLUgwF7Yf$&E;Z{n7FT0o;M3w zkdcAk2SwFn14b)G>B-rQiqg6=XOk$Z%pCgWyK629UvW4D3KsmVpDv z5(XM1&7i=b#-PZc$DqVu$)F6jNDE>Z)FKWBBcK{ZuvPLvRmwoC^?+8ZFsK3@$q3X9 Ha*R3vh#@JJ delta 177 zcmbQsx{rnH)W2Q(7#J8F8I&h-ZJT(bcycbIIitknrHqQ!l0b1j24)~B%)rec!obfU z${+>g@h~s~NdX3F1{omD1e61bNC4TT3@l*v>XR9n)B-nxWkIHhF|Yzj83qmpS)f^R nK%MdoY77cs(-a^&pr&yEWn_UW7=e5qAX@=wJ|lx7*d!$Y+A9%z diff --git a/SMIMS-Game/PlayerTestWorld.java b/SMIMS-Game/PlayerTestWorld.java index abc6190..d133f2c 100644 --- a/SMIMS-Game/PlayerTestWorld.java +++ b/SMIMS-Game/PlayerTestWorld.java @@ -19,6 +19,7 @@ public class PlayerTestWorld extends World super(600, 400, 1); prepare(); } + /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. @@ -29,5 +30,7 @@ public class PlayerTestWorld extends World addObject(ground,260,375); Player player = new Player(); addObject(player,264,237); + JumpBoostItem jumpBoostItem = new JumpBoostItem(); + addObject(jumpBoostItem,206,200); } } diff --git a/SMIMS-Game/PowerUps.class b/SMIMS-Game/PowerUps.class new file mode 100644 index 0000000000000000000000000000000000000000..829f3609e6cf96bbcf0c48f70553f07b52275748 GIT binary patch literal 984 zcmZuwYfsZq7=F$+D2&5~1Ew%hwMT}wGKv7~sTaRsqpH%ejphsXF_T4?zesQ?zJBKPVFiC8>)~K?? z6wV1$J1TAkv5I=ijlH1rW_OV^ZA$`_b1&rl?pv+CPg?oEkXFsX_D1ZK@v7E}^uinhk7 zt0A$3+tk(WM^5a8fq-a@VOe0L-S2h}i;%c0aS!(ycccc&8>lS%Osd&Blf11sVq)o^ z3E2qSOi0=G0`RR#SUG^-*zHT@3X@~yyvkJMfEsI-WKXTPePxDV6Q!MKmVSy3m*l>b_VR9~T&5q-|!d;VpeK*qh z4)K+X93F7i*T6U)a+aw99^o-}0#8oBE8L~vA&gV7?rfk$Pv!p-u!9NH-rv(w6Vw_N zIYj9Q6@f1(H-@;tQRBFxY4eGu3JHM 0){ + collect(); + getWorld().removeObject(this); + } + } + + void collect(){ + Player player = getIntersectingObjects(Player.class).get(0); + player.reveivePowerUp(duration, "dummy"); + } +} diff --git a/SMIMS-Game/images/mushroom.png b/SMIMS-Game/images/mushroom.png new file mode 100644 index 0000000000000000000000000000000000000000..243d613de23d3e94255c7c408683f5146013ac54 GIT binary patch literal 1693 zcmV;O24eY%P)L6*5PBQrzqNb95KU2Xyz{>xQ>wm=DbjRGon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