我试图了解python和pygame的工作原理因此,我正在尝试从以下位置构建此正方形网格:http://programarcadegames.com/index.php?lang=en&chapter=array_backed_grids#step_07设法用10个正方形做行,但是不知何故我坚持通过创建另一个for循环并获得此结果来做实际网格的部分
我的代码如下:
import pygame pygame.init() win = pygame.display.set_mode((728, 728)) tile_width = 64 tile_height = 64 margin = 8 # space between the boxes white = (255, 255, 255) clock = pygame.time.Clock() run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False x, y = margin, margin for column in range(10): for row in range(0, column): rect = pygame.Rect(x, y, tile_width, tile_height) pygame.draw.rect(win, white, rect) x = x + tile_width + margin y = y + tile_width + margin pygame.display.update() pygame.quit()
x
,并且必须在内循环之后而不是内循环中递增y
: