有没有办法让我用一个函数在pygame中改变许多形状的颜色



我正在尝试编写一个带有头发的小丑,用户可以根据用户输入更改颜色。如何将 BLUE 更改为变量以允许用户输入颜色?我只使用过带有数字的函数。

def hair():
pygame.draw.circle(gameWindow, BLUE, (240, 200), 40, 0)
pygame.draw.circle(gameWindow, BLUE, (180, 230), 30, 0)
pygame.draw.circle(gameWindow, BLUE, (300, 230), 30, 0)
pygame.draw.circle(gameWindow, BLUE, (320, 270), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (160, 270), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (210, 230), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (270, 230), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (200, 200), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (280, 200), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (150, 250), 20, 0)
pygame.draw.circle(gameWindow, BLUE, (330, 250), 20, 0)

您可以通过多种方式做到这一点。一种方法是显示具有不同颜色的矩形。当用户单击矩形时,颜色会相应更改,事件循环中如下所示:

for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
# Different buttons here
if yellow_button.collidepoint(pos):
color = YELLOW
if blue_button.collidepoint(pos):
color = BLUE

然后,您只需将代码中的"BLUE"替换为"颜色"。

相关内容

  • 没有找到相关文章

最新更新