Can anyone point out what I'm doing wrong?

Hey all! I was given a task by my Lecturer to make a Baloon popping game but for some reason when I run the code the screen is completely gray. I have absolutely no clue as to how/why this is happening and was wondering if someone could point out what I’m doing wrong. Thanks in advance to anyone who can help me with this!

void setup()
{
_size(500, 500);
_background(0);
}

int bloonX = 250;
int bloonY = 550;
int score = 0;
int difficulty = 10;
int misses = 0;

void draw()
{
_text(“Score:”, 10, 10);
_text(“Misses:”, 10, 20);
_text(str(score), 60, 10);
_text(str(misses), 60, 20);
_bloonX = bloonX - difficulty;
_fill(0,0,255);
_circle (bloonX, bloonY, 55);
_if (mousePressed == true) {
__if (dist(mouseX,mouseY, bloonX, bloonY)< 55) {
___bloonX = 250;
___bloonY = 550;
___difficulty = difficulty + 5;
___score++;
__}
_}
_if (bloonX > -23) {
__misses++;
__bloonX = 250;
__bloonY = 550;
_}
}

not exactly sure what you are trying to achieve but some of your variables are off. you set canvas the height to 500 yet set your circle position to 550 which its of the canvas.

void setup()
{
  size(500, 500);
  background(0);
}

float bloonX = 250;
float bloonY = 450;
int score = 0;
float difficulty = 10;
int misses = 0;

void draw()
{
  background(0);
  text("Score:", 10, 10);
  text("Misses:", 10, 20);
  text(str(score), 60, 10);
  text(str(misses), 60, 20);
  bloonX = bloonX - difficulty;
  fill(255);
  ellipse (bloonX, bloonY, 55,55);
  if (mousePressed == true) {
    println(bloonX,bloonY,mouseX, mouseY);
    if (dist(mouseX, mouseY, bloonX, bloonY)< 55/2) {
      bloonX = 250;
      bloonY = 450;
      difficulty = difficulty + 5;
      score++;
    }
  }
  if (bloonX > -23) {
    misses++;
    bloonX = 250;
    bloonY = 450;
  }
}

oh, thanks, now I can actually see the circle I thought it wasn’t drawing before. basically I’m trying to get the circle to float up, hence the
bloonX = bloonX - difficulty;
does void draw() not remember what it does to variables? I know it repeats itself every 60 seconds but I don’t know why it isn’t then increasing the height of the circle

draw automatically loops by default, unless you call noLoop().

if you want the circle to go up then your code should be bloonY = bloonY - difficulty instead.

thanks for responding to my question, turns out putting the if statement inside void draw() seemed to be what was causing problems, so I put my code inside a few functions instead and that seems to have fixed it!

1 Like