Example #1
0
def create_isometric_grid_lines(width, height, tile_width, tile_height, color, line_width):

    # Grid lines 1
    shape_list = ShapeElementList()

    for tile_row in range(-1, height):
        tile_x = 0
        start_x, start_y = isometric_grid_to_screen(tile_x, tile_row, width, height, tile_width, tile_height)
        tile_x = width - 1
        end_x, end_y = isometric_grid_to_screen(tile_x, tile_row, width, height, tile_width, tile_height)

        start_x -= tile_width // 2
        end_y -= tile_height // 2

        line = create_line(start_x, start_y, end_x, end_y, color, line_width=line_width)
        shape_list.append(line)

    # Grid lines 2
    for tile_column in range(-1, width):
        tile_y = 0
        start_x, start_y = isometric_grid_to_screen(tile_column, tile_y, width, height, tile_width, tile_height)
        tile_y = height - 1
        end_x, end_y = isometric_grid_to_screen(tile_column, tile_y, width, height, tile_width, tile_height)

        start_x += tile_width // 2
        end_y -= tile_height // 2

        line = create_line(start_x, start_y, end_x, end_y, color, line_width=line_width)
        shape_list.append(line)

    return shape_list
Example #2
0
    def create_shapes_lists(self):
        """
        Create one ShapeElementList for each Map row, to avoid updating single,
        humongous list each time new MapNode is revealed. Smaller lists are
        updated faster.

        :return: List[ShapeElementList]
        """
        self.shapes_lists = {
            row: ShapeElementList()
            for row in range(self.rows)
        }
        if self.loaded:
            r, t = self.screen_width - MARGIN_RIGHT, self.screen_height - MARGIN_TOP
            dx, dy = r - self.max_width // 2 - self.width // 2, t - self.max_height
        else:
            dx, dy = self.minimap_left_and_bottom
        self.move_shapes_lists(dx + 9, dy + 60)
        return self.shapes_lists
Example #3
0
    def generate_shapes(self):
        size = sqrt(len(self.tiles))

        shapes = []
        for i, tile in enumerate(self.tiles):
            tx = i % size
            ty = i // size

            cx = TILE_SIZE + tx * TILE_SIZE
            cy = TILE_SIZE + ty * TILE_SIZE

            shape = ShapeElementList()
            for y, row in enumerate(reversed(tile.lines)):
                for x, pxl in enumerate(row):
                    if pxl == "#":
                        shape.append(
                            create_rectangle_filled(
                                cx + x * PIXEL,
                                cy + y * PIXEL,
                                PIXEL,
                                PIXEL,
                                color=WHITE,
                            ))
            shapes.append(shape)

            # Add border
            print(shape.center_x, shape.center_y)
            rect = create_rectangle_outline(
                shape.center_x,
                shape.center_y,
                len(tile.lines) * PIXEL,
                len(tile.lines) * PIXEL,
                RED,
                # border_width=1,
            )
            shapes.append(rect)

        return shapes
Example #4
0
    def draw_hit_box(self, color: Color = BLACK, line_thickness: float = 1):
        """
        Draw a sprite's hit-box.

        The 'hit box' drawing is cached, so if you change the color/line thickness
        later, it won't take.

        :param color: Color of box
        :param line_thickness: How thick the box should be
        """

        if self._hit_box_shape is None:

            # Adjust the hitbox
            point_list = []
            for point in self.hit_box:
                # Get a copy of the point
                point = [point[0], point[1]]

                # Scale the point
                if self.scale != 1:
                    point[0] *= self.scale
                    point[1] *= self.scale

                # Rotate the point
                if self.angle:
                    point = rotate_point(point[0], point[1], 0, 0, self.angle)

                point_list.append(point)

            shape = create_line_loop(point_list, color, line_thickness)
            self._hit_box_shape = ShapeElementList()
            self._hit_box_shape.append(shape)

        self._hit_box_shape.center_x = self.center_x
        self._hit_box_shape.center_y = self.center_y
        self._hit_box_shape.angle = self.angle
        self._hit_box_shape.draw()
Example #5
0
    def create_map_debug_grid(self) -> ShapeElementList:
        grid = ShapeElementList()
        h_offset = TILE_HEIGHT // 2
        w_offset = TILE_WIDTH // 2
        # horizontal lines:
        for i in range(self.game.map.rows):
            y = i * TILE_HEIGHT
            h_line = create_line(0, y, self.game.map.width, y, BLACK)
            grid.append(h_line)

            y = i * TILE_HEIGHT + h_offset
            h2_line = create_line(w_offset, y, self.game.map.width, y, WHITE)
            grid.append(h2_line)
        # vertical lines:
        for j in range(self.game.map.columns * 2):
            x = j * TILE_WIDTH
            v_line = create_line(x, 0, x, self.game.map.height, BLACK)
            grid.append(v_line)

            x = j * TILE_WIDTH + w_offset
            v2_line = create_line(x, h_offset, x, self.game.map.height, WHITE)
            grid.append(v2_line)
        return grid