Note that there are some explanatory texts on larger screens.

plurals
  1. POBreakout(Game Project) -Getting the ball to center the paddle -Java
    primarykey
    data
    text
    <p>My goal is getting the ball to be centered at the paddle even if the value of the ball radius were to change in future versions of the game. My only problem is implementing the correct math formula for the x coordinate of the gameball. I got the y coordinate formula working perfectly.</p> <p>I do not need the correct answer. I just need guidance and suggestions to get the answer.</p> <p>Here is a picture of the java program:</p> <p><a href="http://i33.photobucket.com/albums/d86/warnexus/ball.png" rel="nofollow">http://i33.photobucket.com/albums/d86/warnexus/ball.png</a></p> <p>You can find the code below the comment "// Trouble figuring the math here".</p> <pre><code> /** Radius of the ball in pixels */ private static final int BALL_RADIUS = 500; private void setup_Paddle() { // TODO Auto-generated method stub // x coordinate of the upper left corner // y coordinate of the upper left corner paddle = new GRect(20,20,PADDLE_WIDTH,PADDLE_HEIGHT); paddle.setFilled(true); paddle.setColor(Color.PINK); add(paddle,paddleInitialLocationX,paddleInitialLocationY); } private void setup_Ball() { // Trouble figuring the math here int ballSetUpCoordX = (int) (paddle.getX()); // Good Code! int ballSetUpCoordY = (int) (paddle.getY()-BALL_RADIUS); gameBall = new GOval(BALL_RADIUS,BALL_RADIUS); gameBall.setFilled(true); gameBall.setColor(Color.BLUE); add(gameBall,ballSetUpCoordX,ballSetUpCoordY); } private GOval gameBall; private GRect paddle; private int paddleInitialLocationX = 200; private int paddleInitialLocationY = 500; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload