我无法让我的 pygame GUI 按钮在我创建的星表上工作,谁能帮我解决这个问题。
我的代码
import os,sys,random
import pygame
from pygame.locals import *
pygame.init()
def start_menu(screen):
font = pygame.font.Font('freesansbold.ttf', 40)
image = pygame.Surface((50,50))
image.fill((0,0,0))
pygame.draw.polygon(image,(255,255,255),[(200,200),(0,50),(25,25)],5)
pos = 1
option1 = font.render("BEGIN",True,(255,255,255))
option2 = font.render("MY PROFILE",True,(255,255,255))
option3 = font.render("INSTRUCTIONS",True,(255,255,255))
option4 = font.render("QUIT",True,(255,255,255))
N = 200
SCREEN_W, SCREEN_H = (900, 600)
pygame.init()
pygame.display.set_caption('Starts Ja')
background = pygame.Surface(screen.get_size())
background = background.convert()
stars = [
[random.randint(0, SCREEN_W),random.randint(0, SCREEN_H)]
for x in range(N)
]
clock = pygame.time.Clock()
while 1:
for e in pygame.event.get():
if e.type == QUIT:
exit()
elif e.type == KEYDOWN:
if e.key == K_DOWN:
pos += 1
if pos > 4: pos = 1
elif e.key == K_UP:
pos -= 1
if pos < 1: pos = 4
elif e.key == K_RETURN:
if pos == 1:
import MathsvadersReal
elif pos == 4:
exit()
clock.tick(22)
screen.blit(option1,(100,100))
screen.blit(option2,(200,200))
screen.blit(option3,(200,300))
screen.blit(option3,(200,400))
screen.blit(image,(20,pos*100))
background.fill((0,0,0))
for star in stars:
pygame.draw.line(background,
(255, 255, 255), (star[0], star[1]), (star[0], star[1]))
star[0] = star[0] - 1
if star[0] < 0:
star[0] = SCREEN_W
star[1] = random.randint(0, SCREEN_H)
screen.blit(background, (0,0))
pygame.display.flip()
if __name__ == '__start_menu__': start_menu()