edit: sorry for the incorrect title
Hi everyone,
I'm relatively new to java so I need some help by coding my first scenario. The main part is based on the "Boids" (simulation of a flock of birds) but I'm trying to improve this code in some ways. Right now I'm working on implementing birth and death of the birds. I'd like to have one new bird (birth) on every ten birds (so a reproduction rate of 1 "child" per 10 birds) and a death rate of five percent (one death per 20 birds).
My idea was to get the whole amount of birds with getObjects(bird.class) and then multiply this amount with 0.1 (for birth) and 0.05 (for death). At this point we would have the number of how many birds will be added to the world and how many will be remove. Now I'd thought each of these numbers could be put into a seperate while-loop like this:
The same with the number of dead birds with removeObject(bird). Since that would be just the basic process, I have no idea how to really code this...Help would be appreciated :)
int i = 0 while (i < amount of biths) { addObject(new bird(), Greenfoot.getRandomNumber(900), Greenfoot.getRandomNumber(700)); i = i + 1 }