Plattform Verssion 1

This commit is contained in:
2026-09-15 11:53:27 +02:00
parent 903d791b6b
commit d9f0219cf1
18 changed files with 125 additions and 44 deletions
Binary file not shown.
+7 -5
View File
@@ -1,9 +1,11 @@
#BlueJ class context #BlueJ class context
comment0.target=BreakingPlattform 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 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.params=pBreakingCountdown
comment1.target=void\ act() comment1.target=BreakingPlattform(int)
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
comment2.params= comment2.params=
comment2.target=void\ breakPlattform() comment2.target=void\ act()
numComments=3 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
+21 -6
View File
@@ -9,24 +9,39 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class BreakingPlattform extends Plattform 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 * Act - do whatever the BreakingPlattform wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment. * the 'Act' or 'Run' button gets pressed in the environment.
*/ */
public void act() public void act()
{ {
super.act();
if(this.PlayerOnPlattform() && IsBreaking==false) 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() public void breakPlattform()
{ {
if(this.PlayerOnPlattform()) //Animation
{ geloescht=true;
}
} }
} }
Binary file not shown.
+4 -4
View File
@@ -22,17 +22,17 @@ public class MovingPlattform extends Plattform
public void act() public void act()
{ {
// Add your action code here. // Add your action code here.
super.act();
this.bewege(); this.bewege();
super.act();
} }
public void bewege() public void bewege()
{ {
MyWorld theWorld= (MyWorld) this.getWorld(); MyWorld theWorld= (MyWorld) this.getWorld();
move(speed); this.setLocation(this.getX()+speed, this.getY());
if(this.getX()<5 || this.getX()<=theWorld.getWidth()) if(this.getX()<5 || this.getX()>=theWorld.getWidth()-5)
{ {
this.loescheMich(); speed=speed*(-1);
} }
} }
} }
Binary file not shown.
+3 -1
View File
@@ -7,4 +7,6 @@ comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
comment2.params= comment2.params=
comment2.target=void\ prepare() comment2.target=void\ prepare()
comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n
numComments=3 comment3.params=
comment3.target=void\ act()
numComments=4
+28 -1
View File
@@ -8,7 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/ */
public class MyWorld extends World public class MyWorld extends World
{ {
int PlattformCountdown=20;
/** /**
* Constructor for objects of class MyWorld. * Constructor for objects of class MyWorld.
* *
@@ -19,6 +19,7 @@ public class MyWorld extends World
super(400, 600, 1); super(400, 600, 1);
prepare(); prepare();
} }
/** /**
* Prepare the world for the start of the program. * Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world. * That is: create the initial objects and add them to the world.
@@ -28,4 +29,30 @@ public class MyWorld extends World
Player player = new Player(); Player player = new Player();
addObject(player,302,320); 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
}
}
} }
Binary file not shown.
+10 -4
View File
@@ -8,6 +8,7 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/ */
public class Plattform extends Actor public class Plattform extends Actor
{ {
boolean geloescht= false;
/** /**
* Act - do whatever the Plattform wants to do. This method is called whenever * Act - do whatever the Plattform wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment. * the 'Act' or 'Run' button gets pressed in the environment.
@@ -15,6 +16,10 @@ public class Plattform extends Actor
public void act() public void act()
{ {
this.scrollNachUnten(); this.scrollNachUnten();
if(geloescht)
{
this.loescheMich();
}
// Add your action code here. // Add your action code here.
} }
@@ -24,7 +29,7 @@ public class Plattform extends Actor
setLocation(this.getX(),this.getY()+2); // Nach unten turnen setLocation(this.getX(),this.getY()+2); // Nach unten turnen
if(this.getY()>= welt.getHeight()-5 ||this.getY()<=0) if(this.getY()>= welt.getHeight()-5 ||this.getY()<=0)
{ {
this.loescheMich(); geloescht= true;
} }
} }
@@ -35,10 +40,10 @@ public class Plattform extends Actor
public boolean PlayerOnPlattform() public boolean PlayerOnPlattform()
{ {
Actor Spieler= getOneObjectAtOffset(0, 5, Player.class); Player Spieler= (Player) getOneIntersectingObject(Player.class);
if(Spieler!= null) if(this.isTouching(Player.class))
{ {
if(Spieler.equals(Player.class)) if(Spieler.getY()<this.getY()-20)
{ {
return true; return true;
} }
@@ -51,5 +56,6 @@ public class Plattform extends Actor
{ {
return false; return false;
} }
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 981 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

+50 -21
View File
@@ -1,25 +1,40 @@
#Greenfoot project file #Greenfoot project file
class.BreakingPlattform.image=Unbenannt2.png
class.Ground.image=weave.jpg class.Ground.image=weave.jpg
class.MovingPlattform.image=Unbenannt.png
class.Plattform.image=Plattform.png
class.Player.image=ppl2.png class.Player.image=ppl2.png
dependency1.from=PlayerTestWorld dependency1.from=MyWorld
dependency1.to=Ground dependency1.to=Player
dependency1.type=UsesDependency dependency1.type=UsesDependency
dependency2.from=PlayerTestWorld dependency2.from=MyWorld
dependency2.to=Player dependency2.to=Plattform
dependency2.type=UsesDependency dependency2.type=UsesDependency
dependency3.from=MyWorld dependency3.from=MyWorld
dependency3.to=Player dependency3.to=MovingPlattform
dependency3.type=UsesDependency dependency3.type=UsesDependency
dependency4.from=Player dependency4.from=MyWorld
dependency4.to=Ground dependency4.to=BreakingPlattform
dependency4.type=UsesDependency dependency4.type=UsesDependency
editor.fx.0.height=737 dependency5.from=Player
editor.fx.0.width=814 dependency5.to=Ground
editor.fx.0.x=360 dependency5.type=UsesDependency
editor.fx.0.y=26 dependency6.from=Plattform
height=830 dependency6.to=MyWorld
package.numDependencies=4 dependency6.type=UsesDependency
package.numTargets=4 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
project.charset=UTF-8 project.charset=UTF-8
publish.hasSource=false publish.hasSource=false
publish.locked=true publish.locked=true
@@ -42,28 +57,42 @@ target1.width=120
target1.x=0 target1.x=0
target1.y=0 target1.y=0
target2.height=70 target2.height=70
target2.name=Ground target2.name=MovingPlattform
target2.showInterface=false target2.showInterface=false
target2.type=ClassTarget target2.type=ClassTarget
target2.width=120 target2.width=120
target2.x=0 target2.x=0
target2.y=0 target2.y=0
target3.height=70 target3.height=70
target3.name=PlayerTestWorld target3.name=Ground
target3.showInterface=false target3.showInterface=false
target3.type=ClassTarget target3.type=ClassTarget
target3.width=120 target3.width=120
target3.x=0 target3.x=0
target3.y=0 target3.y=0
target4.height=70 target4.height=70
target4.name=MyWorld target4.name=BreakingPlattform
target4.showInterface=false target4.showInterface=false
target4.type=ClassTarget target4.type=ClassTarget
target4.width=120 target4.width=120
target4.x=0 target4.x=0
target4.y=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 version=3.1.0
width=1550 width=856
world.lastInstantiated=PlayerTestWorld world.lastInstantiated=MyWorld
xPosition=0 xPosition=652
yPosition=0 yPosition=76