Hello!
My name is Robert.
I have to create a mechanic that spawns 4 actors, each representing a truck in a certain color.
That is simple, but the trick is that I have to randomize the order in which they are spawned...
So far I have tried two things:
The above code does spawn the trucks neatly, but not in a random order.
Then I tried using this line for each color truck I had:
This does spawn a lot of trucks in a random order, but it completely fills the screen with trucks which is not what I want of course..
Can anyone assist me?
Thanks!
int randomNummer = 0; for(int i = 0; i < 1; i++){ randomNummer = Greenfoot.getRandomNumber(4); } if (randomNummer == 1) { getWorld().addObject(new TruckBlauw(), 300, 300); } else if (randomNummer == 2){ getWorld().addObject(new TruckGeel(), 400, 400); } else if (randomNummer == 3) { getWorld().addObject(new TruckGroen(), 500, 500); } else if (randomNummer == 4){ getWorld().addObject(new TruckRood(), 200, 200); }
getWorld().addObject(new TruckBlauw(), Greenfoot.getRandomNumber(getWorld().getWidth()), 500);