How to make bullet shoot only when the previous bullet is off the screen

this would be enough:

just check if the bulletFlies and if so, leave

  else if (key == ' ') {
    if (bulletFlies)
      return; // leave
    bulletFlies=true;
    bulletX = gunX+14;
    bulletY = gunY+4;
  }