python - pygame,.tick_busy_loop即使我没有调用它所在的函数也仍然在计算

时间:2014-04-14 20:34:03

标签: python pygame

很抱歉,我不确定他们是否在Python中调用了函数,但我有一个调用.tick_busy_loop(60)的函数来跟踪时间'在我的游戏中。现在,由于某种原因,只要我加载开始菜单,计数器就会启动,而且我无法在调用函数后才加载它。 (当他们选择他们想要的级别时)......

感谢您的任何建议。

代码:

def decide():
     #set variables
    global gameLoop, seconds, minutes, timertf, spritestay, mousepos
    milliseconds = 0

       #start gameLoop for level 1
    while gameLoop:


        for event in pygame.event.get():

            if event.type == pygame.MOUSEBUTTONDOWN:


                #if mouse pos touches sprite, etc..
                mousepos=pygame.mouse.get_pos()
                spritestay = False
                print (mousepos)

            if (event.type==pygame.QUIT):


                gameLoop=False


        #draw window while in game loop
        window.fill((0,0,0))
        window.blit(background, (0,0))

        smallkey.draw()
        leglamp.draw()
        bucket.draw()
        egg1.draw()
        egg2.draw()
        sink.draw()
        bell.draw()
        chicken.draw()
        clock.draw()
        car.draw()
        smartphone.draw()
        doughnut.draw()
        watch.draw()
        hay.draw()
        candle.draw()
        mouse.draw()
        gun.draw()
        goat.draw()
        tape.draw()
        bed.draw()
        spoon.draw()
        plant.draw()
        knife.draw()
        guitar.draw()

        objecttofind.draw()


        #if they beat the level, then stop time
        if levelcompleted==False:

              #timer counting down
            if timertf==False:
                milliseconds = clock1.tick_busy_loop(60) + milliseconds
                if seconds == 0:
                            minutes=minutes-1
                            seconds=59

                if milliseconds > 1000:

                        seconds-=1
                        milliseconds -=1000






          #test format
        timetext =  ("{}:{}".format(minutes, seconds))
        if timertf==False:

            label12 = myfont.render(timetext, 1, (0,0,0))
        elif timertf==False and levelcompleted==True:
            label12 = myfont.render("You Win!", 1, (0,0,0))
        else:
            label12=myfont.render("Time's Up!", 1, (0,0,0))


        if seconds == 0 and minutes == 0:
            objecttofind.i1 = pygame.image.load("images/lose.png")
            timertf = True


        window.blit(label12, (600,50))


        pygame.display.update()
#start menu, welcoming screen for game
while (end_it==False):
    global gameLoop
    window.fill(black)
    myfont=pygame.font.SysFont("Britannic Bold", 40)
    nlabel=myfont.render("Welcome  Start Screen", 1, (255, 0, 0))
    for event in pygame.event.get():
        if event.type==pygame.MOUSEBUTTONDOWN:
            end_it=True
            gameLoop=True
            decide()
    window.blit(nlabel,(200,200))
    pygame.display.flip()

0 个答案:

没有答案