Hello, I'm having trouble checking if a specific object, out of a number of other objects of the same actor class, is still in the world (not removed). Any ideas?
import greenfoot.*;
public class NorthPole extends World
{
private int restoreY;
private int spawnRestoreDelayCount=800;
public NorthPole()
{
super(800, 500, 1);
prepare();
}
public void act()
{
if(spawnRestoreDelayCount>0) //timer to spawn a restore collectable item
{
spawnRestoreDelayCount=spawnRestoreDelayCount-1;
if(spawnRestoreDelayCount==0)
{
spawnRestore();
spawnRestoreDelayCount=Greenfoot.getRandomNumber(1800)+1400;
}
}
}
public void prepare()
{
Counter counter = new Counter("Presents collected: ");
addObject(counter, 97, 21);
Player player = new Player(counter);
addObject(player, 400, 394);
Platform platform1 = new Platform(); //spawns platforms into the world (the ones I want to check if they have been removed or not)
addObject(platform1, 40, 453);
Platform platform2 = new Platform();
addObject(platform2, 120, 453);
Platform platform3 = new Platform();
addObject(platform3, 200, 453);
Platform platform4 = new Platform();
addObject(platform4, 280, 453);
Platform platform5 = new Platform();
addObject(platform5, 360, 453);
Platform platform6 = new Platform();
addObject(platform6, 440, 453);
Platform platform7 = new Platform();
addObject(platform7, 520, 453);
Platform platform8 = new Platform();
addObject(platform8, 600, 453);
Platform platform9 = new Platform();
addObject(platform9, 680, 453);
Platform platform10 = new Platform();
addObject(platform10, 760, 453);
Death death = new Death();
addObject(death, 391, 484);
}
private void spawnRestore() //spawns collectable item
{
restoreY=Greenfoot.getRandomNumber(200)+70;
Restore restore = new Restore();
addObject(restore, 0, restoreY);
}
}
import greenfoot.*;
public class Restore extends Actor
{
public void act()
{
checkBottom();
move(2);
if(isTouching(Bauble.class))
{
getWorld().removeObject(this);
restoreTiles();
}
}
private void restoreTiles() //will restore all removed tiles when called upon
{
}
}for (int i=0; i<10-getWorld().getObjects(Tile.class).size(); i++)
{
// add one tile into world
}