I am currently working on a Pygame project and would like to seek your advice on best practices for organizing my code, particularly when it comes to creating additional scripts. I find myself indecisive with where to place certain functionalities, such as handling grid lines and GUI components. For example I created my
Surface in main file (where the game loop is) and then made a separate file named
grid.py with this code:
def draw_lines(screen: pg.Surface, scroll_x): screen.fill((255, 255, 255)) for line in range(MAX_COL): pg.draw.line(screen, "black", (line * TILE_SIZE - scroll_x, 0), (line * TILE_SIZE - scroll_x, HEIGHT)) for line in range(MAX_ROW): pg.draw.line(screen, "black", (0, line * TILE_SIZE), (WIDTH, line * TILE_SIZE))
then am calling this function every time I iterate through the game loop. (I also need to import this function into my main file)
What I find out about this approach is that am creating many files with usually just a few functions and I wonder if there is some more efficient and elegant way to handle this things. Im open to any suggestions!