I have an actor which points towards the mouse when certain keys are down, and it is touching certain actors. The minimum rotation is meant to be -90 and the maximum is 180. The rotation is converted into a number from 10 to 280 by adding 100. This number is taken from 300 and then used in the 'Greenfoot.getRandomNumber(x)' method. However, I keep getting the 'n must be positive' error, and I have no idea how that can occur. Here is my code:
Anybody know how this is happening? Thanks in advance!
import greenfoot.*;
public class BuretteWheel extends Objects
{
private boolean pickedUp = false;
private int dripSpawnChance = 0;
private boolean initialised = false;
public void act()
{
if (initialised == false)
{
setRotation(-90);
initialised = true;
}
if (pickedUp)
{
if (Greenfoot.getMouseInfo() != null)
{
turnTowards(Greenfoot.getMouseInfo().getX(), Greenfoot.getMouseInfo().getY());
if (Greenfoot.getMouseInfo().getX() < getX() && Greenfoot.getMouseInfo().getY() > getY())
{
if (getRotation() > -135)
{
setRotation(-90);
}
else
{
setRotation(180);
}
}
}
if(Greenfoot.isKeyDown("A") == false
&& Greenfoot.isKeyDown("W") == false
&& Greenfoot.isKeyDown("E") == false
&& Greenfoot.isKeyDown("R") == false
&& Greenfoot.isKeyDown("space") == false)
{
pickedUp = false;
((GameBackdrop) getWorld()).object.objectPickedUp = false;
}
}
else
{
if(Greenfoot.isKeyDown("A") == true && getOneIntersectingObject(Little.class) != null
|| Greenfoot.isKeyDown("W") == true && getOneIntersectingObject(Ring.class) != null
|| Greenfoot.isKeyDown("E") == true && getOneIntersectingObject(Middle.class) != null
|| Greenfoot.isKeyDown("R") == true && getOneIntersectingObject(Index.class) != null
|| Greenfoot.isKeyDown("space") == true && getOneIntersectingObject(Thumb.class) != null)
{
pickedUp = true;
((GameBackdrop) getWorld()).object.objectPickedUp = true;
}
}
dripSpawnChance = getRotation() + 100;
if (Greenfoot.getRandomNumber(300 - dripSpawnChance) == 0 && getRotation() != 0 && ((GameBackdrop) getWorld()).burettefluid.volume > 0)
{
Droplet droplet = new Droplet("Neutralisation Alkali");
((GameBackdrop) getWorld()).addObject(droplet, 400, 375);
}
}
}
