import pygame
pygame.init()
win = pygame.display.set_mode((800, 600))
在数组中列出 pygame 窗口中的所有像素
pts = pygame.PixelArray(win)
创建一些颜色常量
# Colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
GREY = (128, 128, 128)
clicked = False
clock = pygame.time.Clock()
# GAME LOOP
while True:
win.fill(BLACK)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
检查是否单击并按住鼠标左键
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
clicked = True
检查鼠标按钮是否释放
elif event.type == pygame.MOUSEBUTTONUP:
clicked = False
不知道下面是不是有什么问题。
if clicked:
mouse_X, mouse_Y = pygame.mouse.get_pos()
for a in range(mouse_X, mouse_X + 79):
pts[a][mouse_Y:mouse_Y + 60] = GREEN
pygame.display.update()
clock.tick(250)