Advertisement Jump to content


This topic is now archived and is closed to further replies.


Collisions ??? Box/Ball

This topic is 5349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well , i´m stuck, i´m making a pong game , all was fine until I reached the collisions -->

struct struct_ball

double x;
double y;
double vx;
double vy;
double Speed;

struct_ball Ball;

struct struct_pad

double x;
double y;

struct_pad Players[2];

// Right side of the pad --> This work ok

if (((Ball.x >= Players[0].x) && 
(Ball.x <= (Players[0].x+PaddleSprite1->w))) && 

((Ball.y >= Players[0].y) && 
(Ball.y <= (Players[0].y+PaddleSprite1->h))))

		Ball.vx = -Ball.vx;


// Top of the pad --> does not work ! dunno why

if (((Ball.y >= Players[0].y)&& 
(Ball.y <= (Player[0].y+PaddleSprite1->h))) 
&& ((Ball.x >= Players[0].x) && 
(Ball.x <= (Players[0].x+PaddleSprite1->w))))


		Ball.vy = -Ball.vy;



The above piece of code test the Ball against the left pad, but my question is how I can test the top and botton sides of the pad against the ball ? 

Or better , there is another way to test collisions with objects ?
Maybe perfect pixel collision ? can someone show me ?   

Share this post

Link to post
Share on other sites
Don''t you want to take into account the size of the ball? For your tests you use the dimensions of the paddle, but not of the ball.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!