Need help with an assignment from school

I have a problem with the square collecting the circle and i also have a problem with the score text number changing as i collect the coins. I used circleX and circleY to generate random locations after the circle is gotten.

this is what i have so far

float x;
float y;
float circleX;
float circleY;

 
void setup(){
  size (400, 400);
  x = width/2;
  y = height/2;
  circleX = random(0,width);
  circleY = random(0,height);
}
 
void draw(){
  background(0,255,0);
  fill(255,0,0);
  rect(x, y, 20,20);
  fill(0);
 text("Score : ", 0, 15); 
  ellipse(circleX, circleY, 10,10);
}
 
void keyPressed() {
  ellipse(circleX, circleY, 10,10);
  if ((keyPressed == true) && (key == CODED)) {
    if (keyCode == UP){
     y --;
    } else if (keyCode == DOWN) {
      y ++;
    } else if (keyCode == LEFT){
      x --;
    } else if (keyCode == RIGHT) {
      x ++;
    }  
  } 
}
1 Like