I am unsure why the below code does not work. Everything is fine asides from the x value. Is there another way to set a random location using x and y? Thanks, help is appreciated.
1 2 3 4 5 6 7 8 9 10 11 12 | private void findEatFood() // funcion to eat an actor. Specifically Food { Actor thisFood=getOneObjectAtOffset( 0 , 0 ,Food. class ); // is there Food in the current square? if (thisFood!= null ) //there is no Food { Greenfoot.playSound( "Belch.wav" ); //play sound file getWorld().removeObject(thisFood); //removes an actor from the world once it has been eaten. x = Greenfoot.getRandomNumber( 20 ); y = Greenfoot.getRandomNumber( 20 ); } while (!getObjectsAt(x, y, null ).isEmpty()); addObject( new Food(), x, y); } |