Plattform Verssion 1
@@ -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
|
||||
|
||||
@@ -9,24 +9,39 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
public class BreakingPlattform extends Plattform
|
||||
{
|
||||
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;
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,6 @@ comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
|
||||
comment2.params=
|
||||
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
|
||||
numComments=3
|
||||
comment3.params=
|
||||
comment3.target=void\ act()
|
||||
numComments=4
|
||||
|
||||
@@ -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,6 +19,7 @@ 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.
|
||||
@@ -28,4 +29,30 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,10 +40,10 @@ 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()<this.getY()-20)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -51,5 +56,6 @@ public class Plattform extends Actor
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 981 B |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 971 B |
|
After Width: | Height: | Size: 610 B |
|
After Width: | Height: | Size: 167 B |
@@ -1,25 +1,40 @@
|
||||
#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=PlayerTestWorld
|
||||
dependency1.to=Ground
|
||||
dependency1.from=MyWorld
|
||||
dependency1.to=Player
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=PlayerTestWorld
|
||||
dependency2.to=Player
|
||||
dependency2.from=MyWorld
|
||||
dependency2.to=Plattform
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=MyWorld
|
||||
dependency3.to=Player
|
||||
dependency3.to=MovingPlattform
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=Player
|
||||
dependency4.to=Ground
|
||||
dependency4.from=MyWorld
|
||||
dependency4.to=BreakingPlattform
|
||||
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
|
||||
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
|
||||
project.charset=UTF-8
|
||||
publish.hasSource=false
|
||||
publish.locked=true
|
||||
@@ -42,28 +57,42 @@ target1.width=120
|
||||
target1.x=0
|
||||
target1.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=BreakingPlattform
|
||||
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=1550
|
||||
world.lastInstantiated=PlayerTestWorld
|
||||
xPosition=0
|
||||
yPosition=0
|
||||
width=856
|
||||
world.lastInstantiated=MyWorld
|
||||
xPosition=652
|
||||
yPosition=76
|
||||
|
||||