I am making a game where i will have to spawn (food)sources periodically and to perform this i have used if statements. I have used if statements throughout my game but for this one instance it fails to work. The solution is likely simple but I am failing to solve it.
Below, i have included code that is most relevant.
If someone can help me i will be most thankful!
private static final int maxSources = 12;
private static final int sourceSpawnTimeDelay = 3000;
int sourceSpawnTime;public Field()
{
// Create a new world with 750x750 cells with a cell size of 1x1 pixels.
super(750, 750, 1);
Greenfoot.setSpeed(50);
....
sourceSpawnTime++;
spawnSource();
}/**
* Spawns sources while the game is running
*/
public void spawnSource()
{
// if(getObjects(Source.class).size() <= maxSources)
// {
if(sourceSpawnTime >= sourceSpawnTimeDelay)
{
sourceSpawnTime = 0;
int x = Greenfoot.getRandomNumber(getWidth());
int y = Greenfoot.getRandomNumber(getHeight());
addObject(new Source(), x, y);
}
// }
}
