We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I'm a beginner and am still trying to fully grasp processing. I decided, armed with the scarce knowledge that I have, to nonetheless try to program a ball bouncing around the screen that can be interacted it via a board (a line on the cursor), which would change its bouncing direction, etc.
This is the code I came up with so far, but I don't understand why the mouse interaction does not work.
float x = 20;
float y = 400;
float s = 0;
float g = 0.1;
float m = 6;
float inert = 0.75;
void setup() {
size(800,800);
background(255);
}
void draw() {
background(255);
line(mouseX,mouseY-100,mouseX,mouseY+100);
fill(0);
println(y,m,s);
ellipse(x,y,20,20);
x = x + m;
m = m*0.996;
y = y + s;
s = s + g;
inert = inert*0.9999;
if((pmouseX<mouseX) && (mouseY-100<y) && (mouseY+100>y) && (mouseX == x-10)) {
m = m*-1;
}
if(x>width) {
x = width;
m = m*-1;
}
else if (x<0) {
x = 0;
m = m*-1;
}
if(y>int(height)) {
s = s*-inert;
}
}
Can anyone explain please? This part specifically:
if((pmouseX<mouseX) && (mouseY-100<y) && (mouseY+100>y) && (mouseX == x-10)) {
m = m*-1
My idea with this was that if the line touches the ball on the right side, while it's moving left-to-right, the ball would change direction. I keep rechecking the parameters I've given and it all, theoretically, sounds correct. But it does not work. Any help would be appreciated. :)
Answers
mouseX == x-10
better use > or < I guess
this is a simple pong game but I understand that your idea is totally different
this is following your idea more