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.
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){
}
}
}