Загрузка данных


    def draw(self, surface, camera):
        zoom = camera.zoom
        offset_x = camera.x
        offset_y = camera.y
        size = self.cell_size * zoom

        # Видимые границы карты на экране
        screen_rect = surface.get_rect()
        start_x = max(0, int(-offset_x // size))
        end_x = min(self.width, int((screen_rect.width - offset_x) // size) + 1)
        start_y = max(0, int(-offset_y // size))
        end_y = min(self.height, int((screen_rect.height - offset_y) // size) + 1)

        # Отрисовываем только видимую часть
        for y in range(start_y, end_y):
            for x in range(start_x, end_x):
                # color = terrain_dict.get(int(self.terrain[y, x])).color

                rect = pygame.Rect(
                    int(x * size + offset_x),
                    int(y * size + offset_y),
                    int(size + 1),
                    int(size + 1)
                )

                color = self.cell_color[y, x]

                pygame.draw.rect(surface, color, rect)

                # Подсветка выделения
                if self.selected[y, x]:
                    pygame.draw.rect(surface, (255, 255, 0), rect, max(2, int(1 * zoom)))