Пример #1
0
    def __game_loop(self):
        end, save = False, False
        while not end:
            for event in pygame.event.get():
                if event.type == QUIT or (event.type == KEYDOWN
                                          and event.key == K_ESCAPE):
                    logging.info("Quitting Map Editor.")
                    end = True
                if event.type == KEYDOWN and event.key == K_RETURN:
                    if len(self.starts) == 0 and len(self.ends) == 0:
                        logging.info("Quitting Map Editor and Saving level.")
                        end, save = True, True
                    else:
                        print(
                            "You have to put dawn all agent starts and agent ends."
                        )
                if event.type == KEYDOWN and event.key == K_w:
                    self.mode = Mode.WALL
                if event.type == KEYDOWN and event.key == K_s:
                    self.mode = Mode.START
                if event.type == KEYDOWN and event.key == K_f:
                    self.mode = Mode.FINISH
                if event.type == MOUSEBUTTONUP:
                    x, y = pygame.mouse.get_pos()
                    self.__handle_mouse_click(Point(x, y))

        return save
    def __borders_to_drawable(self):
        group = DrawableGroup()
        origin = self.ozomap.get_origin()

        # Horizontal lines
        line_length = self.ozomap.grid.width * self.config.tile_size
        for i in range(self.ozomap.grid.height + 1):
            offset = i * self.config.tile_size
            start = Point(origin.x, origin.y + offset)
            end = Point(origin.x + line_length, origin.y + offset)
            group.add_drawable(Line(start, end, self.config.tile_border_width, Colors.GREY))

        # Vertical lines
        line_length = self.ozomap.grid.height * self.config.tile_size
        for i in range(self.ozomap.grid.width + 1):
            offset = i * self.config.tile_size
            start = Point(origin.x + offset, origin.y)
            end = Point(origin.x + offset, origin.y + line_length)
            group.add_drawable(Line(start, end, self.config.tile_border_width, Colors.GREY))
        return group
 def __positions_to_drawable(self):
     group = DrawableGroup()
     for tile in self.ozomap.map_tile_generator():
         rectangle = Rectangle(Point(tile.origin.x, tile.origin.y), self.config.tile_size, self.config.tile_size)
         if tile.agent_start > 0 and tile.agent_finish > 0:
             group.add_drawable(FillChecker(rectangle, Colors.START, Colors.FINISH))
         elif tile.agent_start > 0:
             group.add_drawable(FillRect(rectangle, Colors.START))
         elif tile.agent_finish > 0:
             group.add_drawable(FillRect(rectangle, Colors.FINISH))
     return group
Пример #4
0
    def __init__(self, origin=Point(0, 0), x_pos=0, y_pos=0, size=0):
        """Initialization of the Tile instance.

        Args:
            origin (Point): Top-left point of the tile
        """
        self.origin, self.x_pos, self.y_pos = origin, x_pos, y_pos
        self.agent_start = 0
        self.agent_finish = 0
        self.__walls = [False] * 4  # [upper, right, bottom, left]
        self.__size = size
Пример #5
0
    def __init__(self, cli, config):
        """Initialization of Configuration from parsed command-line arguments and configuration file.

        Args:
            cli (namespace): Parsed command-line arguments
            config (dict[str, dict[str, float]): Parsed configuration file
        """
        self.map_path = None
        self.solver_path = None

        self.fullscreen = cli.fullscreen
        if self.fullscreen:
            self.window_width = config["display"]["resolution_width"]
            self.window_height = config["display"]["resolution_height"]
        else:
            self.window_width = cli.resolution[0]
            self.window_height = cli.resolution[1]

        self.mm_to_px = \
            ((config["display"]["resolution_width"] / config["display"]["display_width"]) +
             (config["display"]["resolution_height"] / config["display"]["display_height"])) / 2

        self.tile_size = round(config["ozobot"]["tile_size"] * self.mm_to_px)
        self.tile_border_width = math.floor(config["ozobot"]["tile_border_width"] * self.mm_to_px)
        self.line_width = round(config["ozobot"]["line_width"] * self.mm_to_px)
        self.wall_width = round(config["ozobot"]["wall_width"] * self.mm_to_px)
        self.color_code_radius = None
        self.intersection_width = None

        self.max_map_width = math.floor(self.window_width / self.tile_size)
        self.max_map_height = math.floor(self.window_height / self.tile_size)

        self.top_margin = math.floor((self.window_height - (self.tile_size * self.max_map_height)) / 2)
        self.left_margin = math.floor((self.window_width - (self.tile_size * self.max_map_width)) / 2)

        self.map_origin = Point(self.left_margin, self.top_margin)
        self.map_width, self.map_height, self.map_agent_count = [None] * 3

        self.editor = cli.editor

        self.display_grid = None
        self.display_walls = None
        self.agent_class = None
        self.direction_preview = None
        self.step_time = None
        self.tail_lag = None
        self.colors = None
Пример #6
0
    def __draw_tile(self, tile):
        tile_size = self.config.tile_size + 1  # This needs to be done for tile borders to overlap during drawing
        rectangle = Rectangle(Point(tile.origin.x, tile.origin.y), tile_size,
                              tile_size)
        if tile.agent_start > 0 and tile.agent_finish > 0:
            FillChecker(rectangle, Colors.START,
                        Colors.FINISH).draw(self.__screen)
            self.__render_text_in_tile(
                tile, "S: {} / F: {}".format(tile.agent_start,
                                             tile.agent_finish))
        elif tile.agent_start > 0:
            FillRect(rectangle, Colors.START).draw(self.__screen)
            self.__render_text_in_tile(tile, "S: {}".format(tile.agent_start))
        elif tile.agent_finish > 0:
            FillRect(rectangle, Colors.FINISH).draw(self.__screen)
            self.__render_text_in_tile(tile, "F: {}".format(tile.agent_finish))

        Rect(rectangle, self.config.tile_border_width,
             Colors.GREY).draw(self.__screen)
Пример #7
0
 def __compute_corners(center: Point, direction: Directions, width: int):
     half = int(width / 2)
     if direction == Directions.UP:
         return [center.moved(half, half), center.moved(-half, half), center.moved(0, -half)]
     elif direction == Directions.RIGHT:
         return [center.moved(-half, half), center.moved(-half, -half), center.moved(half, 0)]
     elif direction == Directions.DOWN:
         return [center.moved(-half, -half), center.moved(half, -half), center.moved(0, half)]
     elif direction == Directions.LEFT:
         return [center.moved(half, -half), center.moved(half, half), center.moved(-half, 0)]
Пример #8
0
 def __init__(self, start: Point, end: Point, width: int = 1, color=Colors.BLACK):
     self.start, self.end = Point(*start.to_list()), Point(*end.to_list())
     self.width = width
     self.color = color
     self.__elongate()