我有一個GAME OVER畫面,當您的健康狀況消失時,此畫面正在運行。這個GAME OVER屏幕是通過show_go_screen執行的。我試圖將show_go_screen的方法複製到我的另一個屏幕的show_winning()函數中。當我回到遊戲中時,我通過設置你的健康恢復正常來操縱這個節目的獲獎功能。但是,一旦您進入YOU WIN屏幕並返回遊戲,您將無法再次進入YOU WIN屏幕。我已經在下面包含了我的播放器屏蔽代碼(它決定了何時有GAME OVER/YOUWIN事件),我還包括了show_go_screen(用於GAME OVER)和show_winning()方法的代碼(它是爲你贏得屏幕)。如果有人能告訴我如何最好地修改我的代碼以獲得所需的結果。如何在pygame中顯示GAME OVER畫面和YOU WIN畫面
if TrumpHits:
self.trump.shield -= 25
if self.trump.shield <= 0:
self.show_winning()
self.winning = True
if hits:
self.player.shield -= 20
if flyby:
self.player.shield -= 30
if self.player.shield <= 0:
self.playing = False
這裏是show_go_screen()和show_winning()方法
def show_go_screen(self):
# game over/continue
if not self.running:
return
bg = pg.image.load("GAMEOVERslimeCOVERAGE.png")
self.screen.blit(bg,(0,0))
self.draw_text("Press space bar to play again", 22, WHITE, WIDTH/2, HEIGHT * 7/8)
HEIGHT/2 + 40)
pg.display.flip()
waiting = True
while waiting:
self.clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
waiting = False
self.running = False
if event.type == pg.KEYDOWN:
if event.key == pg.K_SPACE:
waiting = False
self.PlayMusic()
def show_winning(self):
# game over/continue
if self.winning:
return
bg = pg.image.load("TRUMPyouwin3d.png")
self.screen.blit(bg,(0,0))
self.draw_text("Press any key to play again", 22, WHITE, WIDTH/2, HEIGHT * 7/8)
pg.display.flip()
waiting = True
while waiting:
self.clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
waiting = False
self.running = False
if event.type == pg.KEYDOWN:
if event.key == pg.K_SPACE:
waiting = False
self.PlayMusic()
self.player.shield = 100
self.trump.shield = 100
def wait_for_key(self):
waiting = True
while waiting:
self.clock.tick(FPS)
for event in pg.event.get():
if event.type == pg.QUIT:
waiting = False
self.running = False
if event.type == pg.KEYUP:
waiting = False
請勿發佈您的代碼;改爲創建[mcve]。它會讓這個問題對其他人更有利,因爲閱讀,理解,測試/驗證變得更容易,而且這也會讓那些試圖找出問題的人更容易。 –