Public Group

# breakout in opengl

This topic is 3988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013152
×