Hello again, I have a couple of questions with the game im creating right now
For the following actor, I would like to have an random initial rotation (using a random number generator and give it a greater random turn capability than what it is currently shown as below.
Next, I need help with getting the following method to create a condition in which when the actor touches the borders, it will respawn in random areas ONLY in the top half of the world (btw my world is 800x600). The code I have below allows the actor to respawn in random areas anywhere in the world, which I would like to change to what I described above.
Lastly, how would I reset all my variables when the game is either won or lost? Whenever I win/lose, I press reset but the "GAME OVER" or "YOU WIN" text does not disappear, and I have to recompile scenario in order to do so.
public void randomTurn() //Turns at random intervals
{
move(1);
//create condition of probability, occurs 1/20 times or 5%.
if(Greenfoot.getRandomNumber(20)==1)
{
//generate degrees from -30 to 30 inclusive.
turn(Greenfoot.getRandomNumber(61)-30);
}
}public void bounceAtEdges(int width,int height) //
{
int worldX = getWorld().getWidth();
int worldY = getWorld().getHeight();
if(getY()==height) //top border
{
setLocation(Greenfoot.getRandomNumber(worldX) , Greenfoot.getRandomNumber(worldY));
}
if(getX()==width) //left border
{
setLocation(Greenfoot.getRandomNumber(worldX) , Greenfoot.getRandomNumber(worldY));
}
if(getX()==worldX-width) //right border
{
setLocation(Greenfoot.getRandomNumber(worldX) , Greenfoot.getRandomNumber(worldY));
}
if(getY()==worldY-height)//bottom border
{
setLocation(Greenfoot.getRandomNumber(worldX) , Greenfoot.getRandomNumber(worldY));
}
}
