Пример #1
0
    def __init__(self, params=None):
        pygame.init()

        if params is not None:
            self.SCREEN_HEIGHT, self.SCREEN_WIDTH = int(float(params['display']['height']) * SCALE), \
                                                    int(float(params['display']['width']) * SCALE)
            self.FIELD_LIMITS = int(float(params['field_top_left_x']) * SCALE), \
                                int(float(params['field_top_left_y']) * SCALE), \
                                int(float(params['field_bottom_right_x']) * SCALE), \
                                int(float(params['field_bottom_right_y']) * SCALE)
            self.FIELD_SIZE = self.FIELD_LIMITS[2] - self.FIELD_LIMITS[
                0], self.FIELD_LIMITS[3] - self.FIELD_LIMITS[1]
            self.GRID_SIZE = int(float(params['cell']['width']) * SCALE), int(
                float(params['cell']['height']) * SCALE)

        # zoom and centering
        self.offset = 0, 0
        self.zoom_factor = 1.0
        self._old_screen = self.SCREEN_WIDTH, self.SCREEN_HEIGHT

        # setup the screen and the box field of play
        self.initialize_screen()

        # agents
        self.agents = pygame.sprite.Group()
        self.agent_image = pygame.image.load(
            'assets/blueagent.bmp').convert_alpha()
        self.controller = SocialForceController(self)
        # self.controller = RandomController(self)

        # time related items
        self.clock = pygame.time.Clock()
        self.paused = False
        self.simulation_timer = Timer(10, self.simulation_update)

        # create the grid
        self.setup_grid()

        # additional options (remove this)
        self.options = dict(draw_grid=True)

        # setup objects (waypoints, obstacles)
        self.waypoints = dict()
        self.obstacles = []
        self._agent_count = 0

        # initialize the time
        self.time_passed = 0