Sign in to follow this  
cplus programmer

need help

Recommended Posts

this wont work
int pong::collision()
{
    //collison decetion
    //if they hit each other
    if(bypos == ypos-52 && bxpos == xpos-52)
    {
        ypos = -ypos;
        bypos = -bypos;
    }    
    //from the side
    if(bxpos == xpos-52)
    {
        xpos = -xpos;
        bxpos = -bxpos;
    } 
        if(bypos == ypos+52)
    {
        ypos = -ypos;
        bypos = -bypos;
    }    
    //from the side
    if(bxpos == xpos+52)
    {
        xpos = -xpos;
        bxpos = -bxpos;
    }
}    


it goes straight through the other one. when I have this done I can make a game of pong, my 1-year dream ;)

Share this post


Link to post
Share on other sites
Gaiiden    5710
My first suggestion would be to not use the == operator. The reason being is that it's too exact. There may be a chance that you won't catch the values exactly when they equal each other. The better approach is to use >= or <=, because then if you're off by a pixel or two, the condition is still evaluated. And no one will notice if it's off by that small an amount.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this