Hello there,
I am trying to figure out how to an object(Enemy) to spawn in randomly on the edge of the screen and move in a direction that does not make it immediately go off screen(i.e. object spawns on right side of screen and immediately goes to the right). I also want the object to keep spawning in until the user pauses the program.
All I have is this:
Keep in mind that my world size is (700,500) and the object is named Enemy and is constantly moving. If anyone knows how to do what I am trying to make it do, then please tell me.
public void randomSpawn() { if(Greenfoot.getRandomNumber(300) ==1) { int spawnX = 100; int spawnY = 100; int rotate = 0; if(Greenfoot.getRandomNumber(100) ==1) { spawnX += Greenfoot.getRandomNumber(500); spawnY += Greenfoot.getRandomNumber(300); } rotate = Greenfoot.getRandomNumber(360); setRotation(rotate); getWorld().addobject(new Enemy(), spawnX, spawnY); }