#Help with if and booleans/ ball in x/y axis problem
1 messages ยท Page 1 of 1 (latest)
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Sure, I'd be happy to help you with your logic problems. Could you please provide more details about the assignment and the specific problem you are facing?
I hope i am going the right direction with my logic
please note that i am a beginner, and my knowledge is limited, and i am also limited to what i learned in class.
public static void main(String[] args) {
double xLoc=30;
double yLoc=20;
double xVel=5;
double yVel=-5;
final int rightWall=100;
final int ceiling=100;
final double diameter=4;
for (int v = 0; v<Math.abs(yVel) ; v++) {
boolean bounced = false;
// if Velocity is downwards
if (0 > yVel) {
//if hits wall
if (yLoc - v < (diameter / 2)) {
//bounce on y axis
bounced = true;
}
if (bounced) {
yLoc++;
} else {
yLoc--;
}
}
if ((yLoc + v) > ceiling - (diameter / 2)) {
bounced = true;
}
if (bounced) {
yLoc--;
} else {
yLoc++;
}
}
}
}
}
}```
Detected code, here are some useful tools:
Formatted code
public class Main {
public static void main(String[] args) {
double xLoc = 30;
double yLoc = 20;
double xVel = 5;
double yVel = - 5;
final int rightWall = 100;
final int ceiling = 100;
final double diameter = 4;
for (int v = 0; v < Math.abs(yVel); v++) {
boolean bounced = false;
// if Velocity is downwards
if (0 > yVel) {
//if hits wall
if (yLoc - v < (diameter / 2)) {
//bounce on y axis
bounced = true;
}
if (bounced) {
yLoc++;
}
else {
yLoc--;
}
}
if ((yLoc + v) > ceiling - (diameter / 2)) {
bounced = true;
}
if (bounced) {
yLoc--;
}
else {
yLoc++;
}
}
}
}
}
}
This is currently what i got, working on the Y axis, i have a problem with my logic on the bounce mechanic of the problem, but not sure how to improve it