0

I'm happy to say I'm still learning and new to making and building quite anything in code so far, but I have been tackling the Tcod Roguelike tutorial to try some things out.

I have gotten to the procedural generation of rooms and have gotten it to work, but I have not been able to figure out how to build a circular room using the library and tools that they have in place. As an idea, here's the base normal code:

class RectangularRoom:
    def __init__(self, x: int, y: int, width: int, height: int):
        self.x1 = x
        self.y1 = y
        self.x2 = x + width
        self.y2 = y + height

    @property
    def center(self) -> Tuple[int, int]:
        center_x = int((self.x1 + self.x2) / 2)
        center_y = int((self.y1 + self.y2) / 2)

        return center_x, center_y

    @property
    def inner(self) -> Tuple[int, int]:
        """Return the inner area of this room as a 2D array index."""
        return slice(self.x1 + 1, self.x2), slice(self.y1 +1, self.y2)
    
    def intersects(self, other: RectangularRoom) -> bool:
        """Return True if this room overlaps with another RectangularRoom."""
        return(
            self.x1 <= other.x2
            and self.x2 >= other.x1
            and self.y1 <= other.y2
            and self.y2 >= other.y1
        )

The procedural generator fills in the x, y, width, and height values then carves out an array of rectangular rooms.

I tried using to build a circular room by getting the appropriate variables to write the equation of a circle but have run into ValueErrors. As a note, I'm not having the procedural generator make anything with this, so I just have a set singular "Room" to fill in the values. I'm positive I have too much going on, but I really just have no idea where to go with this.

class CircularRoom:
    # I need radius and circumference
    def __init__(self, x:int, y: int, h: int, k: int, r: int):
        self.x0 = x
        self.y0 = y
        self.x1 = h
        self.y1 = k
        self.r0 = r
        self.x2 = int(m.sqrt(r ** 2 - (y - k) ** 2) + h)
        self.y2 = int(m.sqrt(r ** 2 - (x - h) ** 2) + k)

I know there are tools like Turtle and Matplotlib, but I want to draw within this without using those if I have to. If it comes down to it, I'll use those sources, but I want to believe (and I'm positive it's possible) that I can make a circular room in Tcod

Kol
  • 1

0 Answers0