def main(): # change the current directory to the one of the game # this is to allow executions like ``python src/tct.py'' try: os.chdir(os.path.abspath(os.path.dirname(sys.argv[0]))) except IOError as e: print(e) exit(constants.FILE_ERR) # get the command line options; return the option flags game_opts = get_parsed_opts() # MVC stuff event_manager = EventManager() gui_view = MainGUIView(event_manager, game_opts) # the game manager game_manager = GameManager(game_opts) # controller which handles the main game loop main_controller = MainController(event_manager, gui_view, game_manager) # keep running the game until a quit event occurs main_controller.run() # if control somehow reaches this point close all the pygame subsystems pygame.quit() safe_exit()
def main(): # change the current directory to the one of the game os.chdir(os.path.abspath(os.path.dirname(sys.argv[0]))) # parse, get game's command line # options, return options' flags game_opts = get_parsed_opts() # make the window of the game always centered os.environ["SDL_VIDEO_CENTERED"] = "1" # set up the pygame system for the game pygame.init() # create game's window screen pygame.display.set_mode( (constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT), pygame.FULLSCREEN if game_opts.fullscreen else 0) # set game's window title pygame.display.set_caption(GAME_WINDOW_TITLE) # set game's window icon pygame.display.set_icon(load_image( constants.FILES['graphics']['window']['icon'][0])[0]) # hide game's mouse cursor pygame.mouse.set_visible(False) # create the game manager gm = GameManager(game_opts) # main loop flag main_loop_running = True # main game event loop while main_loop_running: # run the game manager gm.run_scene() # on quit exit the game for event in pygame.event.get(): if event.type == pygame.QUIT: main_loop_running = False # uninitialize all the pygame systems pygame.quit()