I am still very new to programming...so hopefully I can get some help here :)
I am now making a small game where you (Fish) want to eat Badfish. There is only 1 Badfish in the world at once, and when that one is eaten, a new one will spawn in a random spot. The thing is, I want the new one to spawn at least 100 pixels away from me (Fish).
I now already have a some codes that allow the Badfish to spawn randomly:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /** * Whenever the Badfish has been eaten, a new one will randomly generated in the world */ private void createNewBadfish() { Badfish newBadfish; newBadfish = new Badfish(); World world; world = getWorld(); int worldWidth = world.getWidth(); int worldHeight = world.getHeight(); int x = Greenfoot.getRandomNumber(worldWidth); int y = Greenfoot.getRandomNumber(worldHeight); world.addObject(newBadfish, x, y); } |