# 需要导入模块: from pygame import locals [as 别名]
# 或者: from pygame.locals import QUIT [as 别名]
def update(self):
“””Called on new frame.”””
self.clock.tick(60)
new_time = time.time()
self.time_delta = new_time – self.last_update_time
self.last_update_time = new_time
self.score += self.energy_per_second * self.time_delta
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYDOWN
and event.key == K_ESCAPE):
self.exit_requested = True
return
if event.type == MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if self.crank.rect.collidepoint(pos):
self.crank.clicked()
for button in self.all_buttons:
if button.rect.collidepoint(pos):
button.clicked()
for machine in self.machines.values():
if machine.rect.collidepoint(pos):
if self.score >= machine.cost:
self.score -= machine.cost
machine.count += 1
self.events.send(f”buy_machine_{machine.name}”)
if self.score >= 5.67e5 and not self.congrats_message:
self.congrats_message = StaticImage((0.5, 0.8), images[“congrats”])
self.gui_plain.add(self.congrats_message)
self.events.send(“win”)
for sprite_layer in self.sprite_layers:
sprite_layer.update()
self.screen.blit(self.background, (0, 0))
self.screen.fill(self.overlay_color, rect=self.overlay1, special_flags=pygame.BLEND_MULT)
self.screen.fill(self.overlay_color, rect=self.overlay2, special_flags=pygame.BLEND_MULT)
for sprite_layer in self.sprite_layers:
sprite_layer.draw(self.screen)
pygame.display.flip()
say(self.events.get_current_message())