So i am currently trying to make my rectangles stop when a mouse touches a rectangle.
Right now it only stop if the mouse reaches a certain Y axis. How can I make it stop when the mouse only touches the square.
int b = 50;
int c = 50;
int d = 50;
int i = 500;
int offset = 1;
int s = 800;
int t = 1100;
int j = 0;
int o = 2000;
int test = 100;
int e = 980;
void setup () {
size(400, 400);
}
void draw () {
background(50);
player();
scoreboard ();
obstacles();
test();
score();
Victory();
failed();
}
void player () {
rect(mouseX-30, mouseY, b, c);
ellipse(mouseX-15, mouseY+20, b-40, c-40);
ellipse(mouseX+5, mouseY+20, b-40, c-40);
rect(mouseX-15, mouseY+30, b-30, c-40);
}
void keyPressed () {
if (key == 'a') {
b += 20;
c += 20;
} else if (key == 's') {
b -= 20;
c -= 20;
} else if (key =='r') {
i += 500;
i += 500;
} else if (key == 't') {
offset = offset -2;
}
}
void score() {
noStroke();
fill(0, 0, 0);
rect(0, 360, 700, 40);
fill(255, 255, 255);
textSize(30);
text(j, 190, 390);
}
void scoreboard () {
if (mouseY < 100) { // need help here
textSize(20);
text("You have ran in to a object!", 20, 100);
offset -= -2;
}
}
void failed () {
if (mouseY > 300) { // need help here
textSize(20);
text("You have ran in to a object!", 20, 100);
offset -= -2;
}
}
void obstacles () {
fill(0, 255, 0);
rect(offset + i, 0, 50, 100);
rect(offset+ i, 300, 50, 100);
rect(offset + t, 300, 50, 100);
rect(offset+ s, 300, 50, 100);
rect(offset + o, -100, 10, 10);
rect(offset + t, 0, 50,100);
rect(offset + s,0,50,100);
rect(offset + e, 0,50,130);
rect(offset + e , 0,50,100);
offset = offset -2;
}
void test () {
textSize(30);
if (mouseX > offset + i) {
text("Points:"+ j, 100, 50);
j = 1;
} else if (mouseX > offset + s) {
j += 2;
}
}
void test2 () {
textSize(30);
if (mouseX < offset + s) {
j = 2;
}
}
void Victory () {
if ( mouseX > offset + o) {
text("You win!", 100, 200);
}
}