Advertisement Jump to content
Sign in to follow this  
Techx

Screen boundries for pong

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

Hey, So I've started work on my pong game in OpenGL, I have the rectangle which is controlled by the left and right arrow keys and it moves around just as it should.. Except.. it flies off the screen onto infinity. How do I detect the boundries of the screen so I can tell it to stop moving once it hits that? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You're entering into the world of collision detection, which is a big subject. Fortunately, the test for what you describe is very simple. It might look something like this:
if (paddleX < leftBoundary + paddleWidth/2)
paddleX = leftBoundary + paddleWidth/2;
else if (paddleX > rightBoundary - paddleWidth/2)
paddleX = rightBoundary - paddleWidth/2;
If that doesn't make immediate sense, try drawing a picture and I'm sure it will become clear.

Share this post


Link to post
Share on other sites
You don't detect the boundaries. You should be able to compute the boundaries given the parameters sent to glFrustum or glOrtho.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!