我的代码将运行没有错误,但它不会显示

时间:2014-04-10 01:22:23

标签: python-2.7 menu pygame

我正在尝试为我正在做的游戏创建一个菜单,这是菜单的代码,但是当我运行它时,它不会显示窗口。

你能帮我找到我的错误,以便显示菜单窗口吗?

这是我的代码:

导入pygame 来自pygame.locals import *

课程菜单:

def __init__(self, options):
    self.options = options
    self.font = pygame.font.Font("dejavu.ttf", 20)
    self.select = 0
    self.total = len(self.options)
    self.keep_pressing = False

def update(self):

    k = pygame.key.get_pressed()

    if not self.keep_pressing:
        if k[K_UP]:
            self.select -= 1
        elif k[K_DOWN]:
            self.select += 1
        elif k[K_RETURN]:
            title, function = self.options[self.select]
            print "Opciones"%(title)
            function()

    if self.select < 0:
        self.select = 0
    elif self.select > self.total -1:
        self.select = self.total -1

    self.keep_pressing = k[K_UP] or k[K_DOWN]

def texto(self, screen):

    total = self.total
    indice = 0
    option_height = 25
    x=100
    y=100

    for (title, function) in self.options:
        if indice == self.select:
            color = (0, 200, 0)
        else:
            color = (0, 0, 0)

        image = self.font.render(title, 1, color)
        position = (x, y + option_height * indice)
        indice += 1
        screen.blit(image, position)



def opcion_1():
    print "Opcion 1"
def opcion_2():
    print "Opcion 2"
def opcion_3():
    print "Opcion 3"
def opcion_4():
    print "Opcion 4"



if __name__ == '_main_':

    finish = False
    options = [
        ("Opcion 1"),
        ("Opcion 2"),
        ("Opcion 3"),
        ("Opcion 4")
        ]

    pygame.font.init()
    screen = pygame.display.set_mode((400, 400))
    background = pygame.image.load("negro.jpeg").convert()
    menu = Menu(options)

    while not finish:
        for e in pygame.event.get():
            if e.type == QUIT:
                finish = True
        screen.blit(background, (0, 0))
        menu.update()
        menu.texto(screen)

        pygame.display.flip()
        pygame.time.delay(10)

0 个答案:

没有答案