question about collision detection
Hey Im currently making my very first game (a pong game =\ )
and I have come to the point where I need to use collision detection (unless theres some other way I dont know of??).
Anyway I was wondering what would be an EASY way of knowing when my ball (GL_POINTS) and my bar (GL_LINES) collides so I can change the direction of the ball.
Any help is appreciated thx!
How about loop through all of the possible points of collision on the line and see if your ball (x,y) position is equal to the point?
check if the height, y-value of the ball falls within the range of the paddle...
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}
something like that if thats how your implementing the pong
good luck..
schwags
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}
something like that if thats how your implementing the pong
good luck..
schwags
check if the height, y-value of the ball falls within the range of the paddle...
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}
something like that if thats how your implementing the pong
good luck..
schwags
ie: if((ball.y < paddle.yMax && ball.y > paddle.yMin))
{
//collision!
ball.xSpeed = -ball.xSpeed; //reverse the balls direction
}
else
{//player loses
}
something like that if thats how your implementing the pong
good luck..
schwags
in my pong game i use:
but for somereason the collide counter increases when ball passes above the paddle. it works fine except that, i cant figure out why though maybe someone could help me
if (test.y1 >= player1.y1 && test.height <= player1.y2 && (test.x1 + test.width )== player1.x){player1.collide++;}
but for somereason the collide counter increases when ball passes above the paddle. it works fine except that, i cant figure out why though maybe someone could help me
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement