Original Post
Hi,
I''ve been working on a Pong game, and managed to implement the collision successfully. However, I tried to make sure it would add to the player score when it went off-screen, but instead it freezes or does funny things.
Here''s the source:
The Collide function needs a lot of omtipmizing.
Any ideas?
Thanks in advance,
CloudNine
bool collide(float batheight,float ballwidth,bool playeroropp)
{
if (playeroropp==true)
{
if (ball.x>opp.x-0.25 && ball.y>opp.y-(batheight/2) && ball.y<opp.y+(batheight/2))
{
return true;
}else{
return false;
}
}
if (playeroropp==false)
{
if (ball.x<player.x+0.25 && ball.y>player.y-(batheight/2) && ball.y<player.y+(batheight/2))
{
return true;
}else{
return false;
}
}
}
void UpdateBall()
{
if (ball.y<-2.4f || ball.y>2.2f)
{
ball.speedy=-ball.speedy;
}
ball.x+=ball.speedx;
ball.y+=ball.speedy;
if (collide(0.6f,0.1f,true) && ball.x>3.2)
{
ball.speedx=-ball.speedx;
}else{
ball.x=-3.2;
ball.y=1.6;
player.score+=10;
}
if (collide(0.6f,0.1f,false) && ball.x<-3.3)
{
ball.speedx=-ball.speedx;
}else{
ball.x=-3.2;
ball.y=1.6;
opp.score+=10;
}
}