Exemplo n.º 1
0
class Simulation:
    def __init__(self, world):
        self.world = world
        self.viewer = Window()
        self.is_paused = False

    def run(self):
        clock = pygame.time.Clock()
        while True:

            dt = clock.tick() / 1000  # ellapsed time in seconds
            if not self.is_paused:
                self.world.update(dt)
            events = self._handle_events()
            self.viewer.update(self.world, events)

    def _handle_events(self):
        events = []
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            events.append(event)
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_PAUSE:
                    self.is_paused = not self.is_paused
        return events
Exemplo n.º 2
0
                                 active_bugs=on_play_bugs,
                                 win_size=window.size,
                                 height_offset=HEIGHT_OFFSET)
            bug_found = mouse_clicked(playing_board,
                                      pos,
                                      active_bugs=on_play_bugs)
            if bug_found in on_play_bugs:
                on_play_bugs.remove(bug_found)

            for bug_event in event_list:
                on_play_bugs = bug_event.action(playing_board, on_play_bugs)

    window.draw_background()

    window.draw_surface(text_surface, (50, 50))

    if not len(on_play_bugs):
        bug_text_surface: pygame.Surface = window.render_text(
            f'No bugs left! Congratulations!')
        window.draw_surface(bug_text_surface, (50, 80))
    elif bug_found != Bug.NO_BUG:
        bug_text_surface: pygame.Surface = window.render_text(
            f'Bug {bug_found} found!')
        window.draw_surface(bug_text_surface, (50, 80))

    draw_tile_board(window,
                    board=playing_board,
                    active_bugs=on_play_bugs,
                    height_offset=HEIGHT_OFFSET)
    window.update()