What I want to do is create some sort of a loop that goes back and forth between to states. One will countdown, the other count up.
My code as of now:
This does not work. shotCountDownPlayer ticks down by playerRateOfFire, but stops after one decerment.
private int playersSpeed = 3;
private int shotCountDownPlayer = 60;
private int playerRateOfFire = 2;
private boolean canShoot;
public void act()
{
playerControlsMovement();
playerControlsFiring();
playersShooting();
}
private void playerControlsMovement()
{
if (this != null && Greenfoot.isKeyDown("a"))
{
move(-playersSpeed);
}
if (this != null && Greenfoot.isKeyDown("d"))
{
move(playersSpeed);
}
}
private void playerControlsFiring()
{
MyWorld spaceInvWorld = (MyWorld) getWorld();
worldBullet playersBullet = new worldBullet();
int turretY = getY()-getImage().getHeight()/2;
if (this != null && Greenfoot.isKeyDown("space") && canShoot == true)
{
spaceInvWorld.addObject(playersBullet, getX(), turretY);
}
}
private void playersShooting()
{
while (shotCountDownPlayer >= 60)
{
shotCountDownPlayer = shotCountDownPlayer - playerRateOfFire;
canShoot = true;
}
if (shotCountDownPlayer <= 0)
{
shotCountDownPlayer = shotCountDownPlayer + playerRateOfFire;
canShoot = false;
}
}
}
