PowerUp Items bewegen sich jetzt nach unten und lösen auch nur noch das richtige PowerUp aus

This commit is contained in:
2026-09-17 09:39:47 +02:00
parent 3d047538f1
commit c0c5151c41
17 changed files with 190 additions and 119 deletions
+17 -2
View File
@@ -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;
}
}
}