diff --git a/SMIMS-Game/JumpBoostItem.class b/SMIMS-Game/JumpBoostItem.class new file mode 100644 index 0000000..8ce3e47 Binary files /dev/null and b/SMIMS-Game/JumpBoostItem.class differ 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 4e85413..5090825 100644 Binary files a/SMIMS-Game/Player.class and b/SMIMS-Game/Player.class differ 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 99be99a..cb40e72 100644 Binary files a/SMIMS-Game/PlayerTestWorld.class and b/SMIMS-Game/PlayerTestWorld.class differ 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 0000000..829f360 Binary files /dev/null and b/SMIMS-Game/PowerUps.class differ diff --git a/SMIMS-Game/PowerUps.ctxt b/SMIMS-Game/PowerUps.ctxt new file mode 100644 index 0000000..2145f73 --- /dev/null +++ b/SMIMS-Game/PowerUps.ctxt @@ -0,0 +1,10 @@ +#BlueJ class context +comment0.target=PowerUps +comment0.text=\r\n\ Write\ a\ description\ of\ class\ PowerUps\ 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\ touchedByPlayer() +comment3.params= +comment3.target=void\ collect() +numComments=4 diff --git a/SMIMS-Game/PowerUps.java b/SMIMS-Game/PowerUps.java new file mode 100644 index 0000000..ac9a537 --- /dev/null +++ b/SMIMS-Game/PowerUps.java @@ -0,0 +1,28 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class PowerUps here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class PowerUps extends Actor +{ + int duration; + public void act() + { + touchedByPlayer(); + } + + public void touchedByPlayer(){ + if (getIntersectingObjects(Player.class).size() > 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 0000000..243d613 Binary files /dev/null and b/SMIMS-Game/images/mushroom.png differ diff --git a/SMIMS-Game/project.greenfoot b/SMIMS-Game/project.greenfoot index dbe2520..df58a98 100644 --- a/SMIMS-Game/project.greenfoot +++ b/SMIMS-Game/project.greenfoot @@ -1,25 +1,44 @@ #Greenfoot project file class.Ground.image=weave.jpg +class.JumpBoostItem.image=mushroom.png class.Player.image=ppl2.png dependency1.from=PlayerTestWorld dependency1.to=Ground dependency1.type=UsesDependency +dependency10.from=MovingPlattform +dependency10.to=MyWorld +dependency10.type=UsesDependency dependency2.from=PlayerTestWorld dependency2.to=Player dependency2.type=UsesDependency dependency3.from=MyWorld dependency3.to=Player dependency3.type=UsesDependency -dependency4.from=Player -dependency4.to=Ground +dependency4.from=MyWorld +dependency4.to=Projectile dependency4.type=UsesDependency -editor.fx.0.height=737 +dependency5.from=Player +dependency5.to=GameOverWorld +dependency5.type=UsesDependency +dependency6.from=Player +dependency6.to=Ground +dependency6.type=UsesDependency +dependency7.from=Player +dependency7.to=Projectile +dependency7.type=UsesDependency +dependency8.from=Plattform +dependency8.to=MyWorld +dependency8.type=UsesDependency +dependency9.from=Plattform +dependency9.to=Player +dependency9.type=UsesDependency +editor.fx.0.height=672 editor.fx.0.width=814 -editor.fx.0.x=332 +editor.fx.0.x=456 editor.fx.0.y=64 -height=736 -package.numDependencies=4 -package.numTargets=4 +height=830 +package.numDependencies=10 +package.numTargets=11 project.charset=UTF-8 publish.hasSource=false publish.locked=true @@ -41,29 +60,78 @@ target1.type=ClassTarget target1.width=120 target1.x=0 target1.y=0 +target10.height=70 +target10.name=MyWorld +target10.showInterface=false +target10.type=ClassTarget +target10.width=120 +target10.x=0 +target10.y=0 +target11.height=70 +target11.name=Projectile +target11.showInterface=false +target11.type=ClassTarget +target11.width=120 +target11.x=0 +target11.y=0 target2.height=70 -target2.name=Ground +target2.name=MovingPlattform target2.showInterface=false target2.type=ClassTarget target2.width=120 target2.x=0 target2.y=0 target3.height=70 -target3.name=PlayerTestWorld +target3.name=Ground target3.showInterface=false target3.type=ClassTarget target3.width=120 target3.x=0 target3.y=0 target4.height=70 -target4.name=MyWorld +target4.name=PowerUps target4.showInterface=false target4.type=ClassTarget target4.width=120 target4.x=0 target4.y=0 +target5.height=70 +target5.name=JumpBoostItem +target5.showInterface=false +target5.type=ClassTarget +target5.width=120 +target5.x=0 +target5.y=0 +target6.height=70 +target6.name=BreakingPlattform +target6.showInterface=false +target6.type=ClassTarget +target6.width=120 +target6.x=0 +target6.y=0 +target7.height=70 +target7.name=GameOverWorld +target7.showInterface=false +target7.type=ClassTarget +target7.width=120 +target7.x=0 +target7.y=0 +target8.height=70 +target8.name=PlayerTestWorld +target8.showInterface=false +target8.type=ClassTarget +target8.width=120 +target8.x=0 +target8.y=0 +target9.height=70 +target9.name=Plattform +target9.showInterface=false +target9.type=ClassTarget +target9.width=120 +target9.x=0 +target9.y=0 version=3.1.0 -width=856 +width=1550 world.lastInstantiated=PlayerTestWorld -xPosition=509 -yPosition=133 +xPosition=0 +yPosition=0