diff --git a/SMIMS-Game/GameOverWorld.class b/SMIMS-Game/GameOverWorld.class new file mode 100644 index 0000000..64be4d7 Binary files /dev/null and b/SMIMS-Game/GameOverWorld.class differ diff --git a/SMIMS-Game/GameOverWorld.ctxt b/SMIMS-Game/GameOverWorld.ctxt new file mode 100644 index 0000000..e10a681 --- /dev/null +++ b/SMIMS-Game/GameOverWorld.ctxt @@ -0,0 +1,7 @@ +#BlueJ class context +comment0.target=GameOverWorld +comment0.text=\r\n\ Write\ a\ description\ of\ class\ GameOverWorld\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n +comment1.params= +comment1.target=GameOverWorld() +comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ GameOverWorld.\r\n\ \r\n +numComments=2 diff --git a/SMIMS-Game/GameOverWorld.java b/SMIMS-Game/GameOverWorld.java new file mode 100644 index 0000000..8c4621c --- /dev/null +++ b/SMIMS-Game/GameOverWorld.java @@ -0,0 +1,21 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class GameOverWorld here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class GameOverWorld extends World +{ + + /** + * Constructor for objects of class GameOverWorld. + * + */ + public GameOverWorld() + { + // Create a new world with 600x400 cells with a cell size of 1x1 pixels. + super(400, 600, 1); + } +} 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/MyWorld.class b/SMIMS-Game/MyWorld.class index 3f3a62b..26919f8 100644 Binary files a/SMIMS-Game/MyWorld.class and b/SMIMS-Game/MyWorld.class differ diff --git a/SMIMS-Game/MyWorld.java b/SMIMS-Game/MyWorld.java index 3c38b1a..b18d2c8 100644 --- a/SMIMS-Game/MyWorld.java +++ b/SMIMS-Game/MyWorld.java @@ -8,7 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) */ public class MyWorld extends World { - int PlattformCountdown=20; + /** * Constructor for objects of class MyWorld. * @@ -19,7 +19,6 @@ public class MyWorld extends World super(400, 600, 1); prepare(); } - /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. @@ -29,30 +28,4 @@ public class MyWorld extends World Player player = new Player(); addObject(player,302,320); } - - public void act() - { - if(PlattformCountdown==0) //Damit in regelmäßigen Abständen auf jeden Fall eine Plattform auftaucht - { - addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5); - PlattformCountdown=100; - } - PlattformCountdown--; - if(Greenfoot.getRandomNumber(100000)>=99800) - { - addObject(new Plattform(), Greenfoot.getRandomNumber(400), 5); - } - if(Greenfoot.getRandomNumber(100000)>=99900) - { - addObject(new MovingPlattform(2), Greenfoot.getRandomNumber(400), 6); //Nach Rechts bewegende Plattform - } - if(Greenfoot.getRandomNumber(100000)>=99900) - { - addObject(new MovingPlattform(-2), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform - } - if(Greenfoot.getRandomNumber(100000)>=99750) - { - addObject(new BreakingPlattform(50), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform - } - } } diff --git a/SMIMS-Game/Player.class b/SMIMS-Game/Player.class index ff9a79d..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 9dcc8a3..5208ed6 100644 --- a/SMIMS-Game/Player.ctxt +++ b/SMIMS-Game/Player.ctxt @@ -1,5 +1,6 @@ #BlueJ class context comment0.target=Player +comment0.text=\r\n\ Write\ a\ description\ of\ class\ Player\ 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= @@ -8,4 +9,10 @@ comment3.params= comment3.target=void\ jump() comment4.params= comment4.target=void\ fall() -numComments=5 +comment5.params= +comment5.target=boolean\ collision() +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 dbe19ac..2abc718 100644 --- a/SMIMS-Game/Player.java +++ b/SMIMS-Game/Player.java @@ -1,19 +1,32 @@ -import greenfoot.*; +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) +/** + * Write a description of class Player here. + * + * @author (your name) + * @version (a version number or a date) + */ public class Player extends Actor { - private int speed = 4; - private int jumpStrength = 12; - private int gravity = 1; + int jumpBoostDuration = -1; + int jumpBoostStrength = 5; + + private int speed = 6; + private int currentJumpStrength; + private int defaultJumpStrength = 15; + private int gravity = 1; + private int verticalSpeed = 0; private boolean onGround = false; public void act() { + collision(); moveLeftAndRight(); jump(); fall(); + handlePowerUps(); } // Bewegung nach links und rechts @@ -35,32 +48,43 @@ public class Player extends Actor { if (Greenfoot.isKeyDown("space") && onGround) { - verticalSpeed = -jumpStrength; + verticalSpeed = -currentJumpStrength; onGround = false; } } - // Schwerkraft und Boden-Kollision + // Schwerkraft private void fall() { + int oldY = getY(); + verticalSpeed += gravity; int newY = getY() + verticalSpeed; - // Prüfen, ob wir auf Ground landen setLocation(getX(), newY); Actor ground = getOneIntersectingObject(Ground.class); - if (ground != null) + if (ground != null && verticalSpeed >= 0) { - // Wenn wir fallen, stehen wir auf dem Ground - if (verticalSpeed >= 0) - { - int groundTop = ground.getY() - ground.getImage().getHeight() / 2; - int characterHalfHeight = getImage().getHeight() / 2; + int groundTop = ground.getY() + - ground.getImage().getHeight() / 2; - setLocation(getX(), groundTop - characterHalfHeight); + int characterBottom = getY() + + getImage().getHeight() / 2; + + // Nur landen, wenn der Spieler vorher über dem Boden war + int oldCharacterBottom = oldY + + getImage().getHeight() / 2; + + if (oldCharacterBottom <= groundTop && + characterBottom >= groundTop) + { + setLocation( + getX(), + groundTop - getImage().getHeight() / 2 + ); verticalSpeed = 0; onGround = true; @@ -71,4 +95,35 @@ public class Player extends Actor onGround = false; } } + + public boolean collision(){ + if (getIntersectingObjects(Projectile.class).size()>0) + { + Greenfoot.setWorld(new GameOverWorld()); + return true; + } + else + { + 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/Projectile.class b/SMIMS-Game/Projectile.class new file mode 100644 index 0000000..b45c87f Binary files /dev/null and b/SMIMS-Game/Projectile.class differ diff --git a/SMIMS-Game/Projectile.ctxt b/SMIMS-Game/Projectile.ctxt new file mode 100644 index 0000000..8e3638e --- /dev/null +++ b/SMIMS-Game/Projectile.ctxt @@ -0,0 +1,9 @@ +#BlueJ class context +comment0.target=Projectile +comment0.text=\r\n\ Write\ a\ description\ of\ class\ Projectile\ 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() +comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ Projectile\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n +comment2.params= +comment2.target=void\ falling() +numComments=3 diff --git a/SMIMS-Game/Projectile.java b/SMIMS-Game/Projectile.java new file mode 100644 index 0000000..f3bedb3 --- /dev/null +++ b/SMIMS-Game/Projectile.java @@ -0,0 +1,26 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class Projectile here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Projectile extends Actor +{ + /** + * Act - do whatever the Projectile wants to do. This method is called whenever + * the 'Act' or 'Run' button gets pressed in the environment. + */ + public void act() + { + falling(); + } + + public void falling(){ + setLocation(getX(), getY() + 5); + if(getY() > getWorld().getHeight() -5){ + getWorld().removeObject(this); + } + } +} diff --git a/SMIMS-Game/images/Projectile1.jpeg b/SMIMS-Game/images/Projectile1.jpeg new file mode 100644 index 0000000..1875f86 Binary files /dev/null and b/SMIMS-Game/images/Projectile1.jpeg differ diff --git a/SMIMS-Game/images/Projectile1.png b/SMIMS-Game/images/Projectile1.png new file mode 100644 index 0000000..20705b7 Binary files /dev/null and b/SMIMS-Game/images/Projectile1.png differ diff --git a/SMIMS-Game/images/bluerock.jpg b/SMIMS-Game/images/bluerock.jpg new file mode 100644 index 0000000..24e88ce Binary files /dev/null and b/SMIMS-Game/images/bluerock.jpg differ 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 0bd4334..f079710 100644 --- a/SMIMS-Game/project.greenfoot +++ b/SMIMS-Game/project.greenfoot @@ -1,40 +1,25 @@ #Greenfoot project file -class.BreakingPlattform.image=Unbenannt2.png class.Ground.image=weave.jpg -class.MovingPlattform.image=Unbenannt.png -class.Plattform.image=Plattform.png class.Player.image=ppl2.png -dependency1.from=MyWorld -dependency1.to=Player +dependency1.from=PlayerTestWorld +dependency1.to=Ground dependency1.type=UsesDependency -dependency2.from=MyWorld -dependency2.to=Plattform +dependency2.from=PlayerTestWorld +dependency2.to=Player dependency2.type=UsesDependency dependency3.from=MyWorld -dependency3.to=MovingPlattform +dependency3.to=Player dependency3.type=UsesDependency -dependency4.from=MyWorld -dependency4.to=BreakingPlattform +dependency4.from=Player +dependency4.to=Ground dependency4.type=UsesDependency -dependency5.from=Player -dependency5.to=Ground -dependency5.type=UsesDependency -dependency6.from=Plattform -dependency6.to=MyWorld -dependency6.type=UsesDependency -dependency7.from=Plattform -dependency7.to=Player -dependency7.type=UsesDependency -dependency8.from=MovingPlattform -dependency8.to=MyWorld -dependency8.type=UsesDependency -editor.fx.0.height=811 -editor.fx.0.width=816 -editor.fx.0.x=1009 -editor.fx.0.y=241 -height=736 -package.numDependencies=8 -package.numTargets=6 +editor.fx.0.height=737 +editor.fx.0.width=814 +editor.fx.0.x=360 +editor.fx.0.y=26 +height=830 +package.numDependencies=4 +package.numTargets=4 project.charset=UTF-8 publish.hasSource=false publish.locked=true @@ -57,42 +42,28 @@ target1.width=120 target1.x=0 target1.y=0 target2.height=70 -target2.name=MovingPlattform +target2.name=Ground target2.showInterface=false target2.type=ClassTarget target2.width=120 target2.x=0 target2.y=0 target3.height=70 -target3.name=Ground +target3.name=PlayerTestWorld target3.showInterface=false target3.type=ClassTarget target3.width=120 target3.x=0 target3.y=0 target4.height=70 -target4.name=BreakingPlattform +target4.name=MyWorld target4.showInterface=false target4.type=ClassTarget target4.width=120 target4.x=0 target4.y=0 -target5.height=70 -target5.name=Plattform -target5.showInterface=false -target5.type=ClassTarget -target5.width=120 -target5.x=0 -target5.y=0 -target6.height=70 -target6.name=MyWorld -target6.showInterface=false -target6.type=ClassTarget -target6.width=120 -target6.x=0 -target6.y=0 version=3.1.0 -width=856 -world.lastInstantiated=MyWorld -xPosition=652 -yPosition=76 +width=1550 +world.lastInstantiated=PlayerTestWorld +xPosition=0 +yPosition=0