I'm working on Breakout and making good progress. I'm at the point where I'd like to add color to the bricks. I've implemented an array of colors that the 'if' loop iterates through to add color. The bricks color perfectly, however the script seems to mess up the paddle initialization.
If I do not add color to the bricks, then the paddle initializes. If I try and add color to the bricks, the paddle does not initialize.
Any idea what might be happening?
Regards!
Alex
// Initializes window with a grid of bricks.
void initBricks(GWindow window)
{
for (int r = 0; r < ROWS; r++)
{
for (int c = 0; c < COLS; c++)
{
char *colors[] = {"00FFFF", "FF00FF","FFFF00", "000000"};
GRect initBricks = newGRect((2 + (c * 40)), (50 + (r * 15)), 36, 10);
setColor(initBricks, colors[r]);
setFilled(initBricks, true);
add(window, initBricks);
}
}
}
// Instantiates paddle in bottom-middle of window.
GRect initPaddle(GWindow window)
{
GRect initPaddle = newGRect(170, 540, 60, 12);
setColor(initPaddle, "000000");
setFilled(initPaddle, true);
add(window, initPaddle);
while (true)
{
GEvent event = getNextEvent(MOUSE_EVENT);
if (event != NULL)
{
if (getEventType(event) == MOUSE_MOVED)
{
double x = getX(event) - 30;
setLocation(initPaddle, x, 540);
}
}
}
return NULL;
}