class InputManager(object):
    def __init__(self, window):
        super().__init__()
        self.state_stack = StateStack()
        self._joystick = None
        self._use_joystick = False
        self.quit = False
        self.paused = False
        self.window = window

    @property
    def buttons(self):
        return pygame.key.get_pressed()

    def update(self, dt):
        #events = self.window.events

        # Check globally for quit event
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.quit = True
                self.state_stack.push(GameState.QUIT)
            elif event.type == pygame.KEYDOWN:
                print(event.dict["key"])

    def _load_joystick(self):
        if pygame.joystick.get_count() > 0 and self._joystick is None:
            self._joystick = pygame.joystick.Joystick(0)
            self._joystick.init()
            self._use_joystick = True

    def _quit_joystick(self):
        pass
 def __init__(self, window):
     super().__init__()
     self.state_stack = StateStack()
     self._joystick = None
     self._use_joystick = False
     self.quit = False
     self.paused = False
     self.window = window
 def __init__(self):
     self.state_stack = StateStack()
     self.state_stack.push(GameState.QUIT)
     self.state_stack.push(GameState.MAIN_MENU)
     self.window = pygame.display.set_mode([800, 600])  # Window(800, 600)
     self.running = True
     self.clock = pygame.time.Clock()
     self.state_dict = {GameState.MAIN_MENU: Dummy()}
     self.input = InputManager(self.window)
     flock_manager.init()
class Application(object):
    def __init__(self):
        self.state_stack = StateStack()
        self.state_stack.push(GameState.QUIT)
        self.state_stack.push(GameState.MAIN_MENU)
        self.window = pygame.display.set_mode([800, 600])  # Window(800, 600)
        self.running = True
        self.clock = pygame.time.Clock()
        self.state_dict = {GameState.MAIN_MENU: Dummy()}
        self.input = InputManager(self.window)
        flock_manager.init()

    def run(self):
        while self.running:
            self.window.fill((0, 0, 0))
            dt = self.clock.tick(60) / 1000.0

            self.input.update(dt)

            if self.state_stack[-1] is GameState.QUIT:
                return

            if self.state_dict[self.state_stack[-1]].is_done:
                self.state_stack.pop()
                continue  # Skip over the rest of this, we need to check if we quit

            flock_manager.update(dt)
            flock_manager.render(self.window)

            self.state_dict[self.state_stack[-1]].update(dt)
            self.state_dict[self.state_stack[-1]].draw(self.window)
            pygame.display.flip()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("QUITTING")