Jump to content
  • Advertisement
Sign in to follow this  
cplus programmer

need help

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!