def game_loop(self):
self.screen = pygame.display.get_surface()
self.clock = pygame.time.Clock()
self.load_assets()
self.font_large = pygame.font.Font(self.font_path, 72)
self.font = pygame.font.Font(self.font_path, 24)
self.font_small = pygame.font.Font(self.font_path, 14)
self.bold_font_large = pygame.font.Font(self.bold_font_path, 72)
self.bold_font = pygame.font.Font(self.bold_font_path, 24)
self.bold_font_small = pygame.font.Font(self.bold_font_path, 14)
pygame.display.set_caption(self.title)
pygame.display.set_icon(self.game_icon)
self.difficulty = "Easy"
self.starting_scene = scenes.TitleScene
self.active_scene = self.starting_scene(self)
while self.active_scene != None:
pressed_keys = pygame.key.get_pressed()
# Event filtering
filtered_events = []
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit_attempt = True
elif event.type == pygame.KEYDOWN:
alt_pressed = pressed_keys[pygame.K_LALT] or \
pressed_keys[pygame.K_RALT]
if event.key == pygame.K_ESCAPE:
self.quit_attempt = True
elif event.key == pygame.K_F4 and alt_pressed:
self.quit_attempt = True
if self.quit_attempt:
self.active_scene.Terminate()
else:
filtered_events.append(event)
self.active_scene.ProcessInput(filtered_events, pressed_keys)
self.active_scene.Update()
self.active_scene.Render()
if not self.active_scene.override_render:
pygame.display.flip()
self.active_scene = self.active_scene.next
self.clock.tick(self.fps)
评论列表
文章目录