Phil, what did you not understand about this code I posted?
</p><div>struct TBrick {</div>
<div> int XPosition;</div>
<div> int YPosition;</div>
<div> int XSize;</div>
<div> int YSize;</div>
<div> uint32_t Color;</div>
<div> uint32_t ActiveState; // 0 is deactive; If it takes multiple hits to kill a brick, it can start greater than 1</div>
<div>};</div>
<div> </div>
<div>struct TBall {</div>
<div> int XPosition;</div>
<div> int YPosition;</div>
<div> int XSize;</div>
<div> int YSize;</div>
<div> int XSpeed;</div>
<div> int YSpeed;</div>
<div>};</div>
<div> </div>
<div>#define BRICK_COLUMNS 20 // how many bricks in a column</div>
<div>#define BRICK_ROWS 10 // how many bricks ina row</div>
<div>#define BRICK_START_X 60 // Where the bricks start on the x-axis</div>
<div>#define BRICK_START_Y 40 // Where the bricks start on the y-axis</div>
<div>#define BRICK_WIDTH 30 // brick width in pixels</div>
<div>#define BRICK_HEIGHT 15 // brickheight in pixels</div>
<div> </div>
<div>// make this a global array</div>
<div>TBrick BrickArray[BRICK_COLUMNS][BRICK_ROWS];</div>
<div> </div>
<div>// Initialize the Brick Array somewhere at the start of your code</div>
<div>for (int x = 0; x < BRICK_COLUMNS; x++) {</div>
<div> for (int y = 0; y < BRICK_ROWS; y++) {</div>
<div> BrickArray[x][y].XSize = BRICK_WIDTH;</div>
<div> BrickArray[x][y].YSize = BRICK_HEIGHT;</div>
<div> BrickArray[x][y].XLocation = BRICK_START_X + x*BRICK_WIDTH;</div>
<div> BrickArray[x][y].YLocation = BRICK_START_Y + y*BRICK_HEIGHT;</div>
<div> BrickArray[x][y].Color = 0xFFFFFFFF; // white</div>
<div> BrickArray[x][y].ActiveState = 1; // 1 hit to turn off brick</div>
<div> }</div>
<div>}</div>
<div> </div>
<div>// in main loop do this:</div>
<div>// move Ball in X direction, then check collision</div>
<div>Ball.XLocation += Ball.XSpeed;</div>
<div>if (CheckCollision(Ball)) {</div>
<div> // The ball hit something, move to original location and negate X speed</div>
<div> Ball.XLocation -= Ball.XSpeed;</div>
<div> Ball.XSpeed = -Ball.XSpeed;</div>
<div>}</div>
<div> </div>
<div>// Do same for Y movement</div>
<div>Ball.YLocation += Ball.YSpeed;</div>
<div>if (CheckCollision(Ball)) {</div>
<div> // The ball hit something, move to original location and negate Y speed</div>
<div> Ball.YLocation -= Ball.YSpeed;</div>
<div> Ball.YSpeed = -Ball.YSpeed;</div>
<div>}</div>
<div> </div>
<div>RenderBricks();</div>
<div> </div>
<div>... // the rest of the main loop</div>
<div> </div>
<div> </div>
<div>// Here are those functions</div>
<div>bool CheckCollisions(TBall ball)</div>
<div>{</div>
<div> // loop through every brick and see if we've hit it</div>
<div> for (int x = 0; x < BRICK_COLUMNS; x++) {</div>
<div> for (int y = 0; y < BRICK_ROWS; y++) {</div>
<div> // Only check against bricks that are active</div>
<div> if (BrickArray[x][y].ActiveState > 0) {</div>
<div> if (ball.XLocation + ball.XSize < BrickArray[x][y].XLocation ||</div>
<div> ball.YLocation + ball.YSize < BrickArray[x][y].YLocation ||</div>
<div> ball.XLocation > BrickArray[x][y].XLocation + BrickArray[x][y].XSize ||</div>
<div> ball.YLocation < BrickArray[x][y].YLocation + BrickArray[x][y].YSize) {</div>
<div> // It's collided wit brick, decrment Active state of brick and return true</div>
<div> BrickArray[x][y].ActiveState--;</div>
<div> return true;</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div> </div>
<div> // Check if we've hit the paddle and </div>
<div> // Check if we've hit the wall (I'll leave this up to you)</div>
<div>}</div>
<div> </div>
<div>// This Draws the bricks</div>
<div>void RenderBricks()</div>
<div>{</div>
<div> // loop through every brick and draw if active</div>
<div> for (int x = 0; x < BRICK_COLUMNS; x++) {</div>
<div> for (int y = 0; y < BRICK_ROWS; y++) {</div>
<div> if (BrickArray[x][y].ActiveState > 0) {</div>
<div> // Call you GL draw function, whatever it is. it would be simple to do in SFML however</div>
<div> GlDrawRect(BrickArray[x][y].XLocation, BrickArray[x][y].YLocation,</div>
<div> BrickArray[x][y].XSize, BrickArray[x][y].YSize, BrickArray[x][y].Color);</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div>}</div>
<div>