Simple question - but not for me... (Parabole movement)
in
Programming Questions
•
11 months ago
I would like to animate a bouncing ball.
But I dont understand the maths for letting it bounce.
My proffessor told me I should use parabole maths, but I tried whatever and my ball is just moving from left to right.
I could paste my script but it's linked to different Nio's
at least u get the idea: its suppose to be a bouncing ball at the bottom of the screen which bounce back when it collides with the sides of the frame.
Any advice is welcome!
But I dont understand the maths for letting it bounce.
My proffessor told me I should use parabole maths, but I tried whatever and my ball is just moving from left to right.
I could paste my script but it's linked to different Nio's
at least u get the idea: its suppose to be a bouncing ball at the bottom of the screen which bounce back when it collides with the sides of the frame.
Any advice is welcome!
- class Bounce {
// variabelen
int x_loc;
int y_loc;
int x_speed;
int y_speed;
int c; // variabele voor kleur
Bounce_body Lichaam;
Bounce(int c_parameterrood,int c_parametergroen,int c_parameterblauw) {
c = color(c_parameterrood,c_parametergroen,c_parameterblauw);
Lichaam = new Bounce_body(c);
x_loc = 20;
y_loc = 550;
x_speed = 2;
y_speed = 2;
}
void display() {
Lichaam.display(x_loc,y_loc);
}
void move() {
x_loc = x_loc + x_speed;
y_loc = (int) sin(y_loc) + y_speed;
if (x_loc<0 || x_loc>width)x_speed = x_speed * -1;
if (y_loc<0 || y_loc>height)y_speed = y_speed * -1;
}}
1