Hot answers tagged

4 votes
Accepted

Ball bounces just above paddle

detectCollision assumes that the width of your ball is RADIUS*2. You have initialized your ball with a width of RADIUS. So detectCollision will return a collision before the ball hits the paddle.
user avatar
  • 18.3k
2 votes

Why Does the Ball Disappear After Calling move()?

If GDB isn't helping, maybe try using printf directly before and after the move statement, e.g. printf("before: %.2f, %.2f\n", getX(ball), getY(ball)); move(ball, velocity, vertical); printf("after: ...
user avatar
  • 2,625
2 votes
Accepted

Ball moving problems

The ball gets stuck in the paddle when the paddle hits the side of the ball. I'm not particularly sure how exactly you tried to implement if the ball is moving down move the ball up but my ...
user avatar
  • 17.4k
1 vote
Accepted

Pset3 Breakout Ball blatantly ignores velocity change when colliding with wall

Your code isn't reversing the direction after bouncing off a wall, it's setting a specific direction. Look at the following: if (getX(ball) <= 0) { xvelocity = drand48() + 3; xvelocity = -...
user avatar
  • 63.4k
1 vote
Accepted

Breakout -- ball continues bouncing after it moves past paddle

First consider instead of just getY(ball) to also add two times the diameter of the ball so by the time the bottom of the ball hits the bottom of the screen you count a lost life. Also it's not a good ...
user avatar
  • 7,326
1 vote

pset3 Ball not detecting bricks

You should use the second approach like other people suggested. In your code: GObject object = detectCollision(window, ball) if (strcmp(getType(object), "GRect") == 0) { velocityY=-velocityY; }...
user avatar
1 vote

Problems implementing initBall()

I don't understand what you mean by "If I change the ball_diameter value from 24 to something lower (i.e. 20) I get the same segmentation fault error. That makes me think that it is value-related." ...
user avatar
  • 36
1 vote

Breakout: Bouncing the Ball Up and Down

If the ball is moving out of the window at the bottom edge, it means that your boundaries are likely not set appropriately. The ball Y coordinate is calculated from the top, left corner of the ball (...
user avatar
  • 1,317
1 vote
Accepted

pset4 Ball is not moving

The ball is never moving because you're having an infinite loop at the beginning of the outer while loop while (lives > 0 && bricks > 0) { while (true) { // do something ...
user avatar
  • 17.4k
1 vote

pset4 Ball is not moving

Are you sure the ball isn't moving? What happens if you lose 3 lives, do you call removeGwindow? If not, the ball may in fact have moved already, and you've lost 3 lives so your ball is frozen (unless ...
user avatar
  • 1,415
1 vote

pset4 Ball is not moving

You don't want the ball to move forever, only when lives>0 and bricks>0. If one of those two conditions are false, your ball should stop moving. Hence, no need to have the forever loop. You want the ...
user avatar
  • 31

Only top scored, non community-wiki answers of a minimum length are eligible