I'm trying to make the ball move to a specific place then falls into the bottom of the app

and this is an quick image I made to make it clear
[IMG]http://img845.imageshack.us/img845/6651/sssssv.gif[/IMG]

and this is what I've been doing , I know it's a mess :S

``````private float ballRadius = 20; // Ball's radius
private float ballX = ballRadius + 150; // Ball's center (x, y)
private float ballY = 350;
private float ballSpeedX = 3;   // Ball's speed for x and y
private float ballSpeedY = 2;
.
.
.

ballX += ballSpeedX;

if (ballX >350) {
ballSpeedX = -ballSpeedX; // Reflect along normal
ballX = ballRadius; // Re-position the ball at the edge
}
else if (ballX + ballRadius > 350) {
ballSpeedX += ballSpeedX;
}
// May cross both x and y bounds
if (ballY - ballX == 280) {
ballSpeedY = 10;
} else if (ballY + ballRadius > BOX_HEIGHT) {
ballSpeedY = -ballSpeedY;
}

.
.
.
.

public void paintComponent( Graphics g ) {
super.paintComponent(g);
// Draw the ball
g.setColor(Color.BLUE);

any help ???

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by loveman47

man, your code really is a mess. try fixing it a little first and then someone will surely help you. this problem is a simple problem that would easily be solved had you provided a complete class, one that includes the imports, a class name, putting pieces of code inside methods... try doing that first friend, I really don't know where to start helping you.

look this is the code that our Dr GAVE IT to us
and I was editing it

``````ballX += ballSpeedX;
ballY += ballSpeedY;
// Check if the ball moves over the bounds
// If so, adjust the position and speed.
if (ballX - ballRadius < 0) {
ballSpeedX = -ballSpeedX; // Reflect along normal
ballX = ballRadius; // Re-position the ball at the edge
} else if (ballX + ballRadius > BOX_WIDTH) {
ballSpeedX = -ballSpeedX;