Pygame - 重置我的主循环

时间:2014-12-05 05:33:51

标签: python python-3.x pygame

我一直在关注一系列试图理解pygame的视频教程,而且代码有点混乱,所以我将所有内容重新整理成整齐的注释块。不幸的是,当你死了,并获得“按r重启”的选项,它只是不起作用。关闭后,每次按下r时,控制台都会弹出错误。

Traceback (most recent call last):
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 104, in <module>
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 69, in gameLoop
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 69, in gameLoop
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 69, in gameLoop
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 69, in gameLoop
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 69, in gameLoop
    gameLoop()
  File "C:\Users\sboe_user\Downloads\Desktop\Python\pygametestin.py", line 102, in gameLoop
    quit()
  File "C:\Python32\lib\site.py", line 362, in __call__
    raise SystemExit(code)
SystemExit: None

我看了整个代码,但我找不到问题。 这是源代码:http://pastebin.com/z2NDfwmj

1 个答案:

答案 0 :(得分:0)

当用户按下r时,您需要重置游戏状态变量,即gameOver = FalsegameExit = False(第二个不是真正需要的,尽管它有助于干净地退出游戏)。< / p>

if event.key == pygame.K_r:
    gameOver = False
    gameExit = False
    reset_vars()
    gameLoop()