diff --git a/SMIMS-Game/BreakingPlattform.class b/SMIMS-Game/BreakingPlattform.class index c6d81c8..c5111c7 100644 Binary files a/SMIMS-Game/BreakingPlattform.class and b/SMIMS-Game/BreakingPlattform.class differ diff --git a/SMIMS-Game/BreakingPlattform.ctxt b/SMIMS-Game/BreakingPlattform.ctxt index 82d1599..4aa6736 100644 --- a/SMIMS-Game/BreakingPlattform.ctxt +++ b/SMIMS-Game/BreakingPlattform.ctxt @@ -1,9 +1,11 @@ #BlueJ class context comment0.target=BreakingPlattform comment0.text=\r\n\ Write\ a\ description\ of\ class\ BreakingPlattform\ 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\ BreakingPlattform\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n +comment1.params=pBreakingCountdown +comment1.target=BreakingPlattform(int) comment2.params= -comment2.target=void\ breakPlattform() -numComments=3 +comment2.target=void\ act() +comment2.text=\r\n\ Act\ -\ do\ whatever\ the\ BreakingPlattform\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n +comment3.params= +comment3.target=void\ breakPlattform() +numComments=4 diff --git a/SMIMS-Game/BreakingPlattform.java b/SMIMS-Game/BreakingPlattform.java index 2fc9b35..64bfea4 100644 --- a/SMIMS-Game/BreakingPlattform.java +++ b/SMIMS-Game/BreakingPlattform.java @@ -8,25 +8,40 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) */ public class BreakingPlattform extends Plattform { - boolean IsBreaking= false; + boolean IsBreaking= false; + int BreakingCountdown; + public BreakingPlattform(int pBreakingCountdown) + { + BreakingCountdown=pBreakingCountdown; + } + /** * Act - do whatever the BreakingPlattform wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { - super.act(); if(this.PlayerOnPlattform() && IsBreaking==false) { - IsBreaking= true; + IsBreaking= true; + //Greenfoot.playSound("...") + this.setImage("BreakingPlattform2.png"); //untested + } + if(IsBreaking) + { + BreakingCountdown--; + if(BreakingCountdown==0) + { + this.breakPlattform(); + } + } + super.act(); } public void breakPlattform() { - if(this.PlayerOnPlattform()) - { - - } + //Animation + geloescht=true; } } 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/MovingPlattform.class b/SMIMS-Game/MovingPlattform.class index 3673817..5f4c1c9 100644 Binary files a/SMIMS-Game/MovingPlattform.class and b/SMIMS-Game/MovingPlattform.class differ diff --git a/SMIMS-Game/MovingPlattform.java b/SMIMS-Game/MovingPlattform.java index 9aca730..8271ab1 100644 --- a/SMIMS-Game/MovingPlattform.java +++ b/SMIMS-Game/MovingPlattform.java @@ -22,17 +22,17 @@ public class MovingPlattform extends Plattform public void act() { // Add your action code here. - super.act(); this.bewege(); + super.act(); } public void bewege() { MyWorld theWorld= (MyWorld) this.getWorld(); - move(speed); - if(this.getX()<5 || this.getX()<=theWorld.getWidth()) + this.setLocation(this.getX()+speed, this.getY()); + if(this.getX()<5 || this.getX()>=theWorld.getWidth()-5) { - this.loescheMich(); + speed=speed*(-1); } } } diff --git a/SMIMS-Game/MyWorld.java b/SMIMS-Game/MyWorld.java index f9688af..17d7f3d 100644 --- a/SMIMS-Game/MyWorld.java +++ b/SMIMS-Game/MyWorld.java @@ -8,9 +8,10 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) */ public class MyWorld extends World { + int PlattformCountdown; int timer = 200; //Zeit, bevor das erste Projektil auftaucht //kann später noch beliebig angepasst werden - + /** * Constructor for objects of class MyWorld. * @@ -30,16 +31,35 @@ public class MyWorld extends World Player player = new Player(); addObject(player,302,320); } - - public void act(){ - if(timer > 0){ - timer = timer - 1; + 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 } else{ Projectile projectile = new Projectile(); addObject(projectile,Greenfoot.getRandomNumber(300)+50,0); timer = 200; //zeitlicher Abstand + if(Greenfoot.getRandomNumber(100000)>=99750) + { + addObject(new BreakingPlattform(50), Greenfoot.getRandomNumber(400), 6); //Nach Links bewegende Plattform } //zwischen den x Werten 50 und 350 spawnen die Projektile (anpassbar) } + } diff --git a/SMIMS-Game/Plattform.class b/SMIMS-Game/Plattform.class index ebbf481..fe23c79 100644 Binary files a/SMIMS-Game/Plattform.class and b/SMIMS-Game/Plattform.class differ diff --git a/SMIMS-Game/Plattform.java b/SMIMS-Game/Plattform.java index 232991c..bc4312b 100644 --- a/SMIMS-Game/Plattform.java +++ b/SMIMS-Game/Plattform.java @@ -8,6 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) */ public class Plattform extends Actor { + boolean geloescht= false; /** * Act - do whatever the Plattform wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. @@ -15,6 +16,10 @@ public class Plattform extends Actor public void act() { this.scrollNachUnten(); + if(geloescht) + { + this.loescheMich(); + } // Add your action code here. } @@ -24,7 +29,7 @@ public class Plattform extends Actor setLocation(this.getX(),this.getY()+2); // Nach unten turnen if(this.getY()>= welt.getHeight()-5 ||this.getY()<=0) { - this.loescheMich(); + geloescht= true; } } @@ -35,12 +40,12 @@ public class Plattform extends Actor public boolean PlayerOnPlattform() { - Actor Spieler= getOneObjectAtOffset(0, 5, Player.class); - if(Spieler!= null) + Player Spieler= (Player) getOneIntersectingObject(Player.class); + if(this.isTouching(Player.class)) { - if(Spieler.equals(Player.class)) + if(Spieler.getY()= 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; @@ -90,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/BreakingPlattform2.png b/SMIMS-Game/images/BreakingPlattform2.png new file mode 100644 index 0000000..431e591 Binary files /dev/null and b/SMIMS-Game/images/BreakingPlattform2.png differ diff --git a/SMIMS-Game/images/MovingPlattform.png b/SMIMS-Game/images/MovingPlattform.png new file mode 100644 index 0000000..1849d5f Binary files /dev/null and b/SMIMS-Game/images/MovingPlattform.png differ diff --git a/SMIMS-Game/images/Plattform.png b/SMIMS-Game/images/Plattform.png new file mode 100644 index 0000000..96dbd34 Binary files /dev/null and b/SMIMS-Game/images/Plattform.png differ diff --git a/SMIMS-Game/images/PlattformProvisorisch.png b/SMIMS-Game/images/PlattformProvisorisch.png new file mode 100644 index 0000000..fb8787f Binary files /dev/null and b/SMIMS-Game/images/PlattformProvisorisch.png differ diff --git a/SMIMS-Game/images/Unbenannt.png b/SMIMS-Game/images/Unbenannt.png new file mode 100644 index 0000000..fd65da7 Binary files /dev/null and b/SMIMS-Game/images/Unbenannt.png differ diff --git a/SMIMS-Game/images/Unbenannt2.png b/SMIMS-Game/images/Unbenannt2.png new file mode 100644 index 0000000..6b3f7a3 Binary files /dev/null and b/SMIMS-Game/images/Unbenannt2.png differ diff --git a/SMIMS-Game/images/a.png b/SMIMS-Game/images/a.png new file mode 100644 index 0000000..1849d5f Binary files /dev/null and b/SMIMS-Game/images/a.png 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 85b2fea..c8dc2be 100644 --- a/SMIMS-Game/project.greenfoot +++ b/SMIMS-Game/project.greenfoot @@ -8,9 +8,13 @@ class.Projectile.image=Projectile1.png class.StartWorld.image=StartBackground.png dependency1.from=GameOverWorld dependency1.to=Button +dependency1.from=PlayerTestWorld +dependency1.to=Ground dependency1.type=UsesDependency dependency2.from=StartWorld dependency2.to=Button +dependency2.from=PlayerTestWorld +dependency2.to=Player dependency2.type=UsesDependency dependency3.from=MyWorld dependency3.to=Player @@ -37,6 +41,19 @@ editor.fx.0.y=65 height=736 package.numDependencies=8 package.numTargets=7 +dependency3.from=MyWorld +dependency3.to=Player +dependency3.type=UsesDependency +dependency4.from=Player +dependency4.to=Ground +dependency4.type=UsesDependency +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 @@ -67,6 +84,7 @@ target2.x=0 target2.y=0 target3.height=70 target3.name=Button +target3.name=PlayerTestWorld target3.showInterface=false target3.type=ClassTarget target3.width=120 @@ -100,8 +118,19 @@ target7.type=ClassTarget target7.width=120 target7.x=0 target7.y=0 +target4.height=70 +target4.name=MyWorld +target4.showInterface=false +target4.type=ClassTarget +target4.width=120 +target4.x=0 +target4.y=0 version=3.1.0 width=856 world.lastInstantiated=StartWorld xPosition=652 yPosition=76 +width=1550 +world.lastInstantiated=PlayerTestWorld +xPosition=0 +yPosition=0