{Basic} How to draw and add more "bullets" as soon as there is space for them?

Hey guys, I'm very new to processing and I'm having a lot of trouble with coming up with the logic of what I need to do.

Basically I'm just making a program which

1) will shoot a bullet from near the bottom of the window when I press the mouse, then travel up, then disappears as it hits near the top of the window. Also

2) as soon as there is enough spacing, another bullet will appear under it and travel with it as well, along with more under the newly appearing bullets. New bullets will keep being added until the first bullet reaches near the top of the page.

Here is what I have so far. Thank you to anyone who can help, and if there is any way to improve my amateur code please let me know! much appreciated, thank you!


// bullets int bullets = 1;

float BY;

float BX = 250;

int bulletSize;

final float BULLET_SPEED = 45;

final float BULLET_SPACING = 50;

final float moving = 0.5;

boolean shoot = false;

int n = 0;

void setup() {

size(500,500);

bulletSize = width/12; }

void draw(){

background(255);

moveShot();

drawShot();

}

void mousePressed() {

if (!shoot) {

BX = 250; 

BY = 450;

}

shoot = true;

}

void drawShot() {

fill(0);

if (shoot) {

 int i = 0;

 while (i < 10) {
  ellipse(BX, BY, BULLET_SIZE, BULLET_SIZE);
  ellipse(BX, BY + (n * BULLET_SPACING), BULLET_SIZE, BULLET_SIZE);
  i++;
 }

}

if (BY < 50) {

shoot = false;

}

}

void moveShot() {

if (shoot && BY > 25) {

BY -= moving;

if (BY % BULLET_SPACING == 0) 

 n++;

}

}

Tagged:

Answers

Sign In or Register to comment.