Sign in to follow this  

breakout in opengl

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

This topic is 3627 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.

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