Hey, I'm trying to create a game and what I'm ultimately stuck on is having a certain object (fish in my case) keep spawning (let's say 3 at a time) until the game ends. any help would be appreciated, thank you.
I guess I'll just make the trigger how it is in that link, I'm new to this so I wouldn't know how to do it on a timer or anything like that haha. Thanks!
public class FishWorld extends World
{
/**
* Constructor for objects of class FishWorld.
*
*/
public FishWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
populateWorld();
moreFood();
}
public void populateWorld()
{
addObject(new Fishy(), 200,100);
addObject(new Shark(), 80, Greenfoot.getRandomNumber(300));
}
public void moreFood()
{
while ((getObjects(Fishfood.class).size ()< 3))
addObject(new Fishfood(), 800, Greenfoot.getRandomNumber(300));
}
}
Having 'moreFood' in the constructor of the world will put the initial food in the world. However, you need to add an 'act' method and call it from there also, so the food count will remain at three.