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

Collisions ??? Box/Ball

This topic is 4948 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