0

Sorry, I'm not sure if they're called functions in Python, but I have one that calls a .tick_busy_loop(60) that keeps track of the 'time' in my game. Now, for some reason, the counter is starting whenever I load the Start Menu, and I can't get it to only load once the function is called. (when they pick which level they want)...

Thanks for any advice.

code:

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 Answers0