2014-12-05 19 views
0

我一直在關注一系列試圖理解pygame的視頻教程,並且代碼有點混亂,所以我將所有內容重新排列成了整齊的註釋塊。不幸的是,當你死亡,並得到「按r重啓」的選項,它不工作。關閉後,每次按r鍵時,控制檯都會彈出錯誤信息。Pygame - 重置我的主循環

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

回答

0

當用戶按下r,你需要重新設置你的遊戲狀態變量,即gameOver = FalsegameExit = False(第二個不是真正需要的,儘管它有助於在遊戲中的清潔退出)。

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