PowerUp Items bewegen sich jetzt nach unten und lösen auch nur noch das richtige PowerUp aus
This commit is contained in:
@@ -9,20 +9,35 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
public class PowerUps extends Actor
|
||||
{
|
||||
int duration;
|
||||
boolean deleteAfterActCycle = false;
|
||||
|
||||
public void act()
|
||||
{
|
||||
moveDown();
|
||||
touchedByPlayer();
|
||||
if (deleteAfterActCycle){
|
||||
getWorld().removeObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void touchedByPlayer(){
|
||||
if (getIntersectingObjects(Player.class).size() > 0){
|
||||
collect();
|
||||
getWorld().removeObject(this);
|
||||
deleteAfterActCycle = true;
|
||||
}
|
||||
}
|
||||
|
||||
void collect(){
|
||||
Player player = getIntersectingObjects(Player.class).get(0);
|
||||
player.reveivePowerUp(duration, "dummy");
|
||||
player.receivePowerUp(duration, "dummy");
|
||||
}
|
||||
|
||||
public void moveDown()
|
||||
{
|
||||
this.setLocation(this.getX(), this.getY()+2);
|
||||
if(this.getY()>=this.getWorld().getHeight())
|
||||
{
|
||||
deleteAfterActCycle = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user