Yeah.. that was just the only way i knew without a for loop and a delay...
public void act()
{
setLocation(getX() + speed, getY());
checkBoundaries();
destroyEnemies();
} move(speed);
public void act()
{
checkKeyPress();
}
/**
* This will check to see if a key has been pressed. If the left arrow is pressed, the turret
* will rotate counterclockwise. If the right arrow is pressed, the turret will turn clockwise.
*/
// add instance field
public int rotation = 0;
// the method
public void checkKeyPress()
{
if (Greenfoot.isKeyDown("left") && rotation >-90)
{
turn(-5);
rotation -= 5;
}
if (Greenfoot.isKeyDown("right") && rotation < 90)
{
turn(5);
rotation += 5;
}
if(Greenfoot.isKeyDown("space"))
{
bullet bullet = new bullet();
bullet.setRotation(rotation);
getWorld().addObject(bullet, getX(), getY());
}
} // add this instance field
private boolean spaceDown;
// replace lines 28 on with
if (!spaceDown && Greenfoot.isKeyDown("space"))
{
spaceDown = true;
bullet bullet = new bullet();
bullet.setRotation(rotation);
getWorld().addObject(bullet, getX(), getY());
}
if (spaceDown && !Geenfoot.isKeyDown("space")) spaceDown = false;
}