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;
ballX = 350 - ballRadius;
}
// May cross both x and y bounds
if (ballY - ballX == 280) {
ballSpeedY = 10;
ballY = ballRadius;
} else if (ballY + ballRadius > BOX_HEIGHT) {
ballSpeedY = -ballSpeedY;
ballY = 70 - ballRadius;
}
.
.
.
.
public void paintComponent( Graphics g ) {
super.paintComponent(g);
// Draw the ball
g.setColor(Color.BLUE);
g.fillOval((int) (ballX - ballRadius), (int) (ballY - ballRadius),
(int)(2 * ballRadius), (int)(2 * ballRadius));
any help ???