I'm programming a shooter and want to have a machine gun where I don't have to klick the mouseButton every time I want to shoot.
Is there a method in Greenfoot which returns true every time the left mouse key is down (like Greenfoot.isKeyDown()) ?
public void act() {
...
mouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getButton() != 0) {
//the gun should shoot but it does only sometimes.
}
...
}// instance variables to be added
int mouseButtonsDown = 0;
int shotDelay = 0;
// code within the act method
if (Greenfoot.mousePressed(null))
{
mouseButtonsDown++;
if (shotDelay == 0) shoot();
}
if (Greenfoot.mouseClicked(null))
{
mouseButtonsDown--;
if (mouseButtonsDown == 0) shotDelay = 0;
}
if (mouseButtonsDown > 0)
{
shotDelay = (shotDelay + 2) % 3;
if (shotDelay == 0) shoot();
}