This site requires JavaScript, please enable it in your browser!
Greenfoot back
radekdv
radekdv wrote ...

2015/1/8

Help with dropping objects.

radekdv radekdv

2015/1/8

#
In my game there are ships moving from left to right while randomly spawning, now i want the ships to drop oil on a random X number. the code that i made for that is private int getRandomNumber(int start, int end) { int normal = Greenfoot.getRandomNumber(end-start+1); return normal+start; } int randomX = getRandomNumber(50,750); if(getWorld() != null && getX() == randomX) { getWorld().addObject(new Oil(), getX(), getY()); } Everything works fine but not every boat drops an oil. any help would be appreciated
danpost danpost

2015/1/8

#
If some or all of your random ships move faster than one pixel per act, they may not actually end up at the location being checked (and therefore, never drop their oil). Please show the entire class code for the Ship objects.
You need to login to post a reply.