import pygame from game_object import GameObject from window import Window from input_manager import InputManager class GameLoop: def __init__(self, window: Window, game_objs: list[GameObject], input_manager: InputManager): self.__window = window self.__game_objs = game_objs self.__input_manager = input_manager @staticmethod def __draw_all(window: Window, game_objs: list[GameObject]) -> None: window.reset() for obj in game_objs: window.draw_object(obj) @staticmethod def __update_all(game_objs: list[GameObject], user_input: int) -> None: for obj in game_objs: obj.update(user_input, game_objs) def run(self, framerate=15): clock = pygame.time.Clock() last_input = None while last_input != InputManager.QUIT: last_input = self.__input_manager.process_input() GameLoop.__update_all(self.__game_objs, last_input) GameLoop.__draw_all(self.__window, self.__game_objs) clock.tick(framerate) pygame.display.flip()