Hot answers tagged

3

If you're following the distribution code, you're likely to have a variable named paddle that stores an instance of your paddle. If the ball collides with the paddle, detectCollision returns an instance of the same paddle (the one stored in paddle). You may think of the value that detect collision returns as an alias to the value stored in paddle. At this ...


1

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 practise to use magic numbers (see 600). Instead use a constant declared at top, and use it in your code. Now aside from that, I don't know what setLocation ...


1

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; } You didn't state that the object is the bricks. Find a way to state that and you'll be fine. Good luck.


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