my objects spawn with a certain probability on the right side of the screen and move to the left side. the problem is that they touch each other very often, i.e.. the images intersect and i don't want that
so i added a code, that a object should check the space before it and when its empty it can be spawned; unfortunately it doesn't work
my code looks like this:
any suggestions how else it could work? or maybe a different solution?
if (Greenfoot.getRandomNumber(200) <1) { if (getObjectsAt(450, Greenfoot.getRandomNumber(400), Enemy.class).isEmpty()) { addObject(new Enemy(), 600, Greenfoot.getRandomNumber(400)); } }