Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

breakout in opengl

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

I am trying to get the ball to scroll off the bottom of the screen. // Reverse direction when you reach left or right edge if (x < -windowWidth || x > windowWidth - rsize) { xstep = -xstep; } // Reverse direction when you reach top edge if (y > windowHeight) { ystep = -ystep; } //??scroll off the bottom edge of the screen?? if (y < -windowHeight) { ystep = -120.0f; } // Actually move the square x = x + xstep; y = y + ystep;

Share this post


Link to post
Share on other sites
Advertisement
I'm curious about a few things here.

I use SDL, but it seems to me that the top-left part of the screen is (0,0). So I don't get your use of -screenHeight and -screenWidth.

And for making the ball go off the bottom, what's wrong with just letting it go and NOT altering its velocity when it does?

Tell us how your code actually behaves in the game.

Share this post


Link to post
Share on other sites
Now I quess your windowWidth means something like 640, 800, etc. :)

rsize = ball size?

Test against the maximum works, but not against the zero. Here is the fixed one :


// Reverse direction when you reach left or right edge
if (x < rsize || x > windowWidth - rsize)
{
xstep = -xstep;
}

// Reverse direction when you reach top or down edge
if (y < rsize || y > windowHeight - rsize)
{
ystep = -ystep;
}

// Actually move the square
x = x + xstep;
y = y + ystep;


Try that.

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!