如何在激活碰撞時讓我的“游戲結束”文本保持亮起?
我制作了一個帶有多個下落立方體的小游戲,玩家(正方形)必須避開它。我設法使碰撞起作用,但問題是每次圓形和正方形碰撞時,每次碰撞時都會顯示文本。但我希望當圓形和方形第一次發生碰撞時,文本會繼續顯示。有什么辦法嗎?import pygamefrom pygame.locals import *import osimport randomimport mathimport sysimport timewhite = (255,255,255)blue = (0,0,255)gravity = 10size =10height = 500width =600varHeigth = heightballNum = 5eBall = []apGame = pygame.display.set_mode((width, height))pygame.display.set_caption("AP Project")clock = pygame.time.Clock()class Player(object): def __init__(self): red = (255, 0, 0) move_x = 300 move_y = 400 self.rect = pygame.draw.rect(apGame,red, (move_x, move_y, 10, 10)) self.dist = 10 def handle_keys(self): for e in pygame.event.get(): if e.type == pygame.QUIT: pygame.quit(); exit() key = pygame.key.get_pressed() if key[pygame.K_LEFT]: self.draw_rect(-1, 0) elif key[pygame.K_RIGHT]: self.draw_rect(1, 0) elif key[pygame.K_ESCAPE]: pygame.quit(); exit() else: self.draw_rect(0, 0) def draw_rect(self, x, y): red = (255, 0, 0) black = (0, 0, 0) '''apGame.fill(black)''' self.rect = self.rect.move(x * self.dist, y * self.dist); pygame.draw.rect(apGame, red , self.rect) pygame.display.update() def draw(self,surface): red = (255, 0, 0) move_x = 300 move_y = 400 pygame.draw.rect(apGame, red, (move_x, move_y, 10, 10))#The game over text here def show_go_screen(): pygame.font.init() myfont = pygame.font.SysFont("Comic Sans MS", 30) label = myfont.render("Game Over", 1, red) apGame.blit(label, (300,100))def instuct(): pygame.font.init() myfont = pygame.font.SysFont("Comic Sans MS", 15) label = myfont.render("Avoid The Circles", 1, red) apGame.blit(label, (250,450))
查看完整描述