I'm currently trying to instantiate 1 row of bricks before moving on to 5. Before implementing the for loop I made sure I could instantiate 1 brick on the screen, exactly where i want it. No problem there. The problem comes when looping over the length of the constant COLS (10) defined before the main function. For some reason my bricks bunch up with no spacing. Can you see anything glitchy in my function?
// Brick width and height
#define BRICK_W 30
#define BRICK_H 7.5
void initBricks(GWindow window)
{
// set initial brick coordinates
int x_coord = 5;
int y_coord = 10;
// Create 10 columns of bricks
for (int i = 0; i < COLS; i++)
{
// create a brick
GRect brick = newGRect(x_coord, y_coord, BRICK_W, BRICK_H);
setFilled(brick, true);
setColor(brick, "RED");
add(window, brick);
// increment x coordinate for spacing
x_coord = x_coord + 10;
}
}
For some reason my bricks just come out bunched together with no spacing towards the upper left of the window. Any thoughts?