如何使用pygame更改输入背景色?

时间:2018-11-03 20:03:32

标签: python pygame

我试图允许用户更改背景的颜色,但是我的程序说我的PlayerIG.hudBackhudText是无效的颜色参数。

我不想使用数量众多的if语句。

任何帮助将非常感谢!

import pygame, time, os, pickle
from pygame.locals import*
pygame.font.init()

win = pygame.display.set_mode((600, 320))
pygame.display.set_caption("PLAYER HUD")
font = pygame.font.SysFont("Rockwell", 30)

clock = pygame.time.Clock()

white = ((255,255,255))
blue = ((0,0,255))
green = ((0,255,0))
red = ((255,0,0))
black = ((0,0,0))
orange = ((255,100,10))
yellow = ((255,255,0))
blue_green = ((0,255,170))
marroon = ((115,0,0))
lime = ((180,255,100))
pink = ((255,100,180))
purple = ((240,0,255))
gray = ((127,127,127))
magenta = ((255,0,230))
brown = ((100,40,0))
forest_green = ((0,50,0))
navy_blue = ((0,0,100))
rust = ((210,150,75))
dandilion_yellow = ((255,200,0))
highlighter = ((255,255,100))
sky_blue = ((0,255,255))
light_gray = ((200,200,200))
dark_gray = ((50,50,50))
tan = ((230,220,170))
coffee_brown =((200,190,140))
moon_glow = ((235,245,255))

class Player:
    def __init__(self, name):
        self.name = name
        self.gold = 0
        self.hudBack = "black"
        self.hudText = "orange"
        self.option1 = False
        self.option = 0
PlayerIG = Player("Player")

def redrawGameWindow():
    if os.path.exists("savefile") == True:
        with open('savefile', 'rb') as f:
            PlayerIG = pickle.load(f)
    win.fill(PlayerIG.hudBack)
    text1 = font.render("GOLD:", 1, PlayerIG.hudText)
    text2 = font.render(str(PlayerIG.gold), 1, PlayerIG.hudText)
    win.blit(text1, (0, 0))
    win.blit(text2, (70, 0))
    pygame.display.update()

run = True
while run:
    clock.tick(27)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    keys = pygame.key.get_pressed()
    if keys[pygame.K_RIGHT]:
        pass
    redrawGameWindow()

pygame.quit()

1 个答案:

答案 0 :(得分:0)

您只需要在RGB值周围放置一组括号,就像这样:

moon_glow = (235,245,255)