All Questions

Community

W
Naim Williams

widening the corridors?

how would you go about widening the corridors?

  • R
    Răzvan Cosmin Rădulescu replied

    Yes so I hoped this is a good homework for anyone that wants to dive in deeper into exploring game development, that's why I didn't provide a solution for this.

    The idea is that we have a direction for the corridors (in our case: horizontal & vertical) and we just traverse a line to save tiles. To widen the corridor we have to also traverse on the other axis. So if our line goes horizontally, then we need to also add tiles on the vertical at each point, perhaps two tiles on each side if we want 3-tiles wide corridors for example.


    Now, I hope that's enough for you to first try it on your own and I'll give you my solution below.

    ---


    Note how I'm calculating the `neighbor` points using the `normal` vector which is 90deg. rotated to our corridor using `axis`.

    ```

    func _add_corridor(data: Dictionary, start: int, end: int, constant: int, axis: int) -> void:
        for t in range(min(start, end), max(start, end) + 1):
            var point := Vector2.ZERO
            match axis:
                Vector2.AXIS_X: point = Vector2(t, constant)
                Vector2.AXIS_Y: point = Vector2(constant, t)
            data[point] = null
     

           var normal := Vector2.DOWN.rotated(axis * PI/2)
            for neighbor in [point - normal, point + normal]:
                data[neighbor] = null

    ```

    Now this introduces these artifacts on the intersections of the corridors so you'll have to dive deeper and experiment a bit to get the look you want.

    Good luck!