so, i'm trying to fix a game where the goal is to click a colored circle that is bouncing around the screen. there is a text prompt at the top saying what color ball to click (the circle's fill is constantly changing). And once you click the right color the background changes to that color, and the circle's fill continues to change. But right now when I click the circle everything changes okay except the text prompt is overlaying the previous one since the background isn't refreshing. Here is the code
Code:
//order: yellow, blue, red, lime
PFont andale;
String tyellow = "YELLOW";
String tred = "RED";
//circ1
float radius = 30.0;
float x = 50.0;
float y = 50.0;
float speedX = 0.6;
float speedY = 1.0;
int directionX = 1;
int directionY = -1;
color c1color = color(255);
color backgroundColor = color(255);
//mouse easing
float mx;
float my;
float targetX, targetY;
float easing = 0.05;
//yellow
float vred = 60;
boolean foundColor = false;
int leniency = 15;
//red
float vredd =
void setup(){
size(480, 320);
smooth();
noStroke();
andale = loadFont("AndaleMono-14.vlw");
textFont(andale);
ellipseMode(RADIUS);
colorMode(HSB, 360, 100, 100);
}
void draw(){
background(backgroundColor);
noCursor();
//text yellow
// fill(0);
// text(tyellow, 400, 20, 70, 70);
//color circ1
if (frameCount % 90 == 0){
float r = random(0, 360);
c1color = color(r, 100, 100);
}
//1st circ
fill(c1color);
noStroke();
ellipse(x, y, radius, radius);
x += speedX * directionX;
if ((x > width-radius) || (x < radius)) {
directionX = -directionX;
}
y += speedY * directionY;
if ((y > height-radius) || (y < radius)){
directionY = -directionY;
}
//mouse easing
targetX = mouseX;
mouseX = constrain(mouseX, 0, width); //mouse or target
float dmx = targetX - mx;
if(abs(dmx) > 1) {
mx += dmx * easing;
}
targetY = mouseY;
mouseY = constrain(mouseY, 0, height); //constrain either mouse or target
float dmy = targetY - my;
if(abs(dmy) > 1) {
my += dmy * easing;
}
stroke(0);
strokeWeight(2);
strokeCap(SQUARE);
line(mx-20, my, mx+20, my);
line(mx, my-20, mx, my+20);
if (foundColor == true) {
//println("Hey, I found it.");
fill(0);
text(tred, 430, 20, 70, 70);
}else if (foundColor == false){
fill(0);
text(tyellow, 400, 20, 70, 70);
}
}
//background change
void mousePressed(){
if(dist(x, y, mouseX, mouseY) < radius) {
backgroundColor = c1color;
if ( vred > hue(c1color) - leniency && vred < hue(c1color) + leniency) {
foundColor = true;
}
}
}