Essentially i just want some guidance on how to make the circle bounce off the movable object. Im having trouble and have been trying for three hours and thus have turned to forums for assistance. I have attempted multiple 'if' statements but clearly I am not understanding properly as none are working. Thank you :)
I have been trying for 3 hours to figure this out with different if statements.
float x;
float easing = 1;
float circle_x = 1;
float circle_y = 30;
float rad = 12.5;
float gravity = 0.98;
float move_x = 5;
float move_y = 5;
void setup() {
size(640, 480);
frameRate(60);
}
void draw() {
background(#87CEEB);
fill(#7cfc00);
rect(0, 430, 640, 80);
float targetX = mouseX;
float dx = targetX - x;
x += dx * easing;
fill(#000000);
rect(x, 400, 30, 30);
rect(x-20, 390, 70, 10);
rect(x, 430, 5, 20);
rect(x+25, 430, 5, 20);
ellipse(circle_x, circle_y, 25, 25);
circle_x = circle_x + move_x;
circle_y = circle_y + move_y;
if (circle_x > width) {
circle_x = width;
move_x = -move_x;
}
if (circle_y > height) {
circle_y = height;
move_y = -move_y;
}
if (circle_x < 0) {
circle_x = 0;
move_x = -move_x;
}
if (circle_y < 0) {
circle_y = 0;
move_y= -move_y;
}
}
Inserting any variables into if statements and only receiving back: the ball being bounced by my mouse cursor (not the object), glitchy circles and stuttery images.