Sorry if this is really specific, but I can't figure this out for the life of me. I have created a version of the game LightsOut, with a grid representing the board. As you can see, I have the grid being drawn twice...? It flickers with mouse movement, and I'm trying to find a way to have that stop. Anyone have ideas? Thanks. Here's the code in question:
size = 5
grid = []
for x in range(5):
column = []
for y in range(5):
column.append(white)
grid.append(column)
#####################################
drawing = True
while drawing:
# MAKES THE GRID #
for a in range(size + 1):
for b in range(size + 1):
r = pygame.Rect(a * 100, b * 100, 100, 100)
border = 0
if grid[a][b] == (0, 0, 0):
border = 5
pygame.draw.rect(w, grid[a][b], r, border)
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
# INVERTS BOXES #
(x, y) = pygame.mouse.get_pos()
grid_x = int(x / 100)
grid_y = int(y / 100)
invert(grid, (grid_x, grid_y))
pygame.display.flip()
############
for grid_x in range(size + 1):
for grid_y in range(size + 1):
rect = pygame.Rect(grid_x * 100, grid_y * 100, 100, 100)
pygame.draw.rect(w, (0, 0, 0), rect, 5)
pygame.display.flip()