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

**URL:** https://discourse.processing.org/t/how-to-make-bullet-shoot-only-when-the-previous-bullet-is-off-the-screen/32314
**Category:** Coding Questions
**Created:** [September 19, 2021, 1:38pm UTC](https://discourse.processing.org/t/how-to-make-bullet-shoot-only-when-the-previous-bullet-is-off-the-screen/32314 "2021-09-19T13:38:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![MarkShaker](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@MarkShaker](https://discourse.processing.org/u/MarkShaker)
#### Post date: [September 19, 2021, 1:38pm UTC](https://discourse.processing.org/t/how-to-make-bullet-shoot-only-when-the-previous-bullet-is-off-the-screen/32314/1 "2021-09-19T13:38:15Z")

</div>

Hi everyone, I’m having trouble with shooting another bullet only when the previous bullet fired is off the screen. This is my current code.

```auto

```

int x = 30;  
int y = 60;  
float gunX = x+20;  
float gunY = y+20;  
float circleY;  
float circleX;  
boolean bulletFlies=false;  
float bulletX = 20;  
float bulletY = 20;

void setup() {  
size(500, 500);  
circleY = random(25,480);  
circleX = 450;  
}

void draw() {  
background(0);  
fill(255, 56, 99);  
ellipse(x, y, 60, 60);  
gunX = x+12;  
gunY = y;  
bullet();

fill(255);  
circle(circleX,circleY, 80);  
circleX=circleX-0.5;

}

void keyPressed() {  
if (key == ‘s’) y = y + 8;  
else if (key == ‘w’) y = y - 8;  
else if (key == ’ ') {  
bulletFlies=true;  
bulletX = gunX+14;  
bulletY = gunY+4;  
}  
}

void bullet() {  
if (bulletFlies) {  
ellipse(bulletX, bulletY, 6, 6);  
bulletX = bulletX+5;  
if (bulletX\>width+12) {  
bulletFlies=false;  
}else if (key == ’ ’ && !bulletFlies){  
}  
}  
}

```auto

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [September 19, 2021, 7:32pm UTC](https://discourse.processing.org/t/how-to-make-bullet-shoot-only-when-the-previous-bullet-is-off-the-screen/32314/2 "2021-09-19T19:32:43Z")

</div>

this would be enough:

just check if the bulletFlies and if so, leave

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

```

---

<div class="post-metadata">

### Author: ![MarkShaker](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@MarkShaker](https://discourse.processing.org/u/MarkShaker)
#### Post date: [September 20, 2021, 2:20am UTC](https://discourse.processing.org/t/how-to-make-bullet-shoot-only-when-the-previous-bullet-is-off-the-screen/32314/3 "2021-09-20T02:20:17Z")

</div>

okay thank you, I will try this
