抱歉,我不确定它们是否在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()
目前没有回答
相关问题 更多 >
编程相关推荐