SpikedPlattforms2
This commit is contained in:
@@ -8,12 +8,51 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
*/
|
||||
public class UnactiveSpike extends Actor
|
||||
{
|
||||
int countdown;
|
||||
int speed;
|
||||
boolean geloescht=false;
|
||||
public UnactiveSpike(int pSpeed, int pCoundown, SpikedPlattform pPlattform)
|
||||
{
|
||||
speed=pSpeed;
|
||||
countdown=pCoundown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Act - do whatever the UnactiveSpike wants to do. This method is called whenever
|
||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||
*/
|
||||
public void act()
|
||||
{
|
||||
// Add your action code here.
|
||||
this.bewege();
|
||||
countdown--;
|
||||
if(countdown==0)
|
||||
{
|
||||
MyWorld theWorld= (MyWorld) this.getWorld();
|
||||
Spike BeispielSpike=new Spike(1);
|
||||
GreenfootImage SpikeImage= BeispielSpike.getImage();
|
||||
theWorld.addObject(new Spike(speed), this.getX(), (this.getY()- this.getImage().getHeight()/2)-10); //die Zahl Minus damit ist endlich passt
|
||||
geloescht=true;
|
||||
}
|
||||
if(geloescht)
|
||||
{
|
||||
this.loescheMich();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void loescheMich()
|
||||
{
|
||||
MyWorld theWorld= (MyWorld) this.getWorld();
|
||||
theWorld.removeObject(this);
|
||||
}
|
||||
|
||||
public void bewege()
|
||||
{
|
||||
this.setLocation(this.getX(), this.getY()+speed);
|
||||
MyWorld theWorld= (MyWorld) this.getWorld();
|
||||
if(this.getY()>=theWorld.getHeight()-5)
|
||||
{
|
||||
geloescht=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user