Trying to get my coins to appear for a certain amount of time if my player touches a red coin. However I can not seem to get the coins to appear once my player touches a red coin at the moment. Here is my code:
Coin class:
Player class:
and my Interface:
public class Coin extends Items implements Appearance
{
private int appearCounter_;
public Coin()
{
super();
appearCounter_ = 0;
}
/**
* Act - do whatever the Coin wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
super.act();
World w = getWorld();
if(appearCounter_ > 0)
{
w.addObject(this, 500, 350);
appearCounter_ --;
}
else if(appearCounter_ <= 0)
{
w.removeObject(this);
}
}
public void appear(int count)
{
appearCounter_ = count;
}
} public void act()
{
// Add your action code here.
super.act();
if(isTouching(RedCoin.class))
{
World w = getWorld();
RedCoin rCoin = (RedCoin)getOneIntersectingObject(RedCoin.class);
w.removeObject(rCoin);
appearItems();
}
}
public void appearItems()
{
List<Appearance> appear = getWorld().getObjects(Appearance.class);
ListIterator<Appearance> appearIter = appear.listIterator();
while(appearIter.hasNext())
{
Appearance a = appearIter.next();
a.appear(450);
}
}public interface Appearance
{
public void appear(int count);
}
