I am making a safari like project like Pokemon when the player walks into the bush (there are 30 bushes in a 5 by 6 grid) and then a random number is generated and if it is between certain numbers that pokemon occurs, but my problem is it my player sits in the bush more then 1 pokemon occur depending on how long i sit in it for. Is there a way that i can make it so it only generates one number and wont repeat until after i walk out of the bush and into it again?
here is my current coding for the pokemon numbers:
if(getOneIntersectingObject(Grass.class) != null)
{
Actor collision = getOneIntersectingObject(Grass.class);
int rng=Greenfoot.getRandomNumber(40);
if (rng<=46 && rng >= 50 ){rng= 1 ;} //checking if the mark is between 100% and 90%
else if (rng<=40 && rng >= 45 ){rng= 2 ;}//checking if the mark is between 89% and 80%
else if (rng<=29 && rng >= 39 ){rng= 3 ;}//checking if the mark is between 79% and 60%
else if (rng<=16 && rng >= 28 ){rng= 4 ;}//checking if the mark is between 59% and 50%
else if (rng<=1 && rng >= 15 ){rng= 5 ;}//checking if the mark is between 49% and 0%
switch (rng) {
case 1:
getWorld().addObject( new Tyranitar(), 120, 20 );
break; //stops the case
case 2:
getWorld().addObject( new Salamence(), 170, 20 );
break; //stops the case
case 3:
getWorld().addObject( new Dragonite(), 220, 20 );
break; //stops the case
case 4:
getWorld().addObject( new Donphan(), 70, 20 );
break; //stops the case
case 5:
getWorld().addObject( new Turtwig(), 20, 20 );
break; //stops the case
}

