44 lines
1019 B
Java
44 lines
1019 B
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class PowerUps here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
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();
|
|
deleteAfterActCycle = true;
|
|
}
|
|
}
|
|
|
|
void collect(){
|
|
Player player = getIntersectingObjects(Player.class).get(0);
|
|
player.receivePowerUp(duration, "dummy");
|
|
}
|
|
|
|
public void moveDown()
|
|
{
|
|
this.setLocation(this.getX(), this.getY()+2);
|
|
if(this.getY()>=this.getWorld().getHeight())
|
|
{
|
|
deleteAfterActCycle = true;
|
|
}
|
|
}
|
|
}
|