pbivens67 said:
I want the ball to hit the brick and then redraw a black brick but not redraw a blue brick.
This would be easier if you would use glColor instead having a texture of assumingly painted bricks.
Anyway, there is a lot permutations which seems not necessary:
drawTopBricks();
drawMiddleBricks();
drawBottomBricks();
eraseBottomBrick(); // also a drawing function
Likely you want to handle all this with just one function to draw the board and eventually another to draw a brick. E.g. like this:
void CalcBrickCoords ( float &br_x, float &br_y, float &br_w, float &br_h,
const int boardX, const int boardY )
{
br_x = float(boardX) * scaleX + offsetX;
br_y = float(boardY) * scaleY + offsetY;
br_w = brickWidth;
br_h = brickHeight;
// those scale and size constants vould be defines / global variables at first, or variables of some level definitions class, etc.
}
void DrawBoard()
{
for (int y=0; y<boardHeight; y++)
for (int x=0; x<boardWidth; x++)
{
int brickType = board[x + y * boardWidth];
if (brickType == 0) // skip if no brick in tht grid cell
continue;
float br_x, br_y, br_w, br_h;
CalcBrickCoords (br_x, br_y, br_w, br_h, x, y);
DrawBrick (br_x, br_y, br_w, br_h, brickType);
}
}
You can reuse the transformation math and DrawBrick() function then to visualize a collision, ensuring coordinates and scaling etc. matches up:
float br_x, br_y, br_w, br_h;
CalcBrickCoords (br_x, br_y, br_w, br_h,
test_coll_brick_x, test_coll_brick_y);
if (coll.collision(b_x, b_y, b_w, b_h, br_x, br_y, br_w, br_h) == 1)
{
DrawBrick (br_x, br_y, br_w, br_h, blackBrickType);
}