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)
python类K_RALT的实例源码
def process_event(self, event):
# perf: local for faster access
io = self.io
if event.type == pygame.MOUSEMOTION:
io.mouse_pos = event.pos
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
io.mouse_down[0] = 1
if event.button == 2:
io.mouse_down[1] = 1
if event.button == 3:
io.mouse_down[2] = 1
if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
io.mouse_down[0] = 0
if event.button == 2:
io.mouse_down[1] = 0
if event.button == 3:
io.mouse_down[2] = 0
if event.button == 4:
io.mouse_wheel = .5
if event.button == 5:
io.mouse_wheel = -.5
if event.type == pygame.KEYDOWN:
for char in event.unicode:
code = ord(char)
if 0 < code < 0x10000:
io.add_input_character(code)
io.keys_down[event.key] = True
if event.type == pygame.KEYUP:
io.keys_down[event.key] = False
if event.type in (pygame.KEYDOWN, pygame.KEYUP):
io.key_ctrl = (
io.keys_down[pygame.K_LCTRL] or
io.keys_down[pygame.K_RCTRL]
)
io.key_alt = (
io.keys_down[pygame.K_LALT] or
io.keys_down[pygame.K_RALT]
)
io.key_shift = (
io.keys_down[pygame.K_LSHIFT] or
io.keys_down[pygame.K_RSHIFT]
)
io.key_super = (
io.keys_down[pygame.K_LSUPER] or
io.keys_down[pygame.K_LSUPER]
)
if event.type == pygame.VIDEORESIZE:
io.display_size = event.size