Birdoggydog's Builds

Making stairs turn corners and adding spiral stairs in Godot

Stairs and ramps now climb round a corridor's bend by angle, round rooms can have several floor heights, and a new spiral shaft joins floors.

Stairs in the dungeons now turn a corner as they climb. A round room can have a raised half and a sunken middle and still be one round room. And there’s a new spiral stair, a round shaft with treads winding round a steel column. The dungeon generator can lay both when I ask it to.

53 seconds: a turning stair in the cyberpunk theme, the same in steampunk, a round room on three heights, a spiral within a floor, a spiral between two floors, and the turning stair at full meat.

This was the third step of my plan for dungeon verticality: heights and stairs first, then round rooms and curves, then curves that rise and fall. Ducts and jagged levels come after. I also said I wanted spiral stairs in this step.

How does a stair climb round a bend?

Before, a stair on a corridor corner climbed along a line and the corner was just a flat square. Now the code finds the corner’s inner point, the square’s corner between the two open sides. The floor’s height at any point depends on its angle round that point, from the edge it comes in by (0) to the edge it leaves by (1). Height is a straight blend between the low and high values over that share of the turn. A smoothed run of half-meter steps uses the second half of the turn, so the steps flow into one slope.

For collision the quarter turn is cut into 24 sectors, and each one is a convex prism. Each corner of a prism has its top at its own share of the turn. My first version clipped a wedge whose apex sat on the square’s corner and dropped some sectors, which left a hole in the floor. So now each sector’s polygon is worked out directly: the corner, where the first ray leaves the square, the far corner if it lies between, and where the last ray leaves.

What you see is treads for a stair, each one a sector no taller than the riser, with a hazard stripe on its edge. A ramp is drawn as 24 pieces. The corridor’s outer wall rounds as on any curved corner.

How do you fit a spiral into one square?

A spiral is a thing on the sheet, either inside a floor joining two heights or between two stacked floors like a ladder. The shaft is one square, 3 meters, across. Its wall is 6-degree facets 1.45 meters from the middle, with a 0.22 meter column and a doorway at each end.

The tricky part is the winding, so there’s a fit step. The treads run from the way in to the way out with a flat landing at each end. It tries up to six whole turns and keeps the gentlest one where the slope 0.9 meters from the middle is at most 36 degrees, since bodies can only walk 45. Every point also needs 2.2 meters of head room under the turn above, because the party is 1.8 meters tall. If nothing fits, the sheet gets an error saying what to change.

One square only fits some rises. Straight through it fits 1.5 and 4.5 to 5 meters, and round a corner 1.5 to 2.5 and 3.5 to 6 meters. Bodies up to 0.9 meters across can walk it, and wider monsters stop at the doorway. A two by two shaft would fit every rise and the big bodies, but that’s later.

What does the generator lay?

With --rising on it lays two things. First, it sinks a room by 1 meter and makes each way into it a stair, out to the first right-angled corner within 6 squares, with at least one way turning. Second, it finds a square of corridor whose removal splits the floor in two, and puts a spiral there, sinking the far part by the first of 3.5, 4, 2.5 or 4.5 meters that a winding fits. If the ground refuses a spiral or a hard check fails, it takes what it laid off again. With the option off, which is the default, all 24 generated outputs I compared came out byte-identical.

The generator’s corridors run mostly straight, so there are few corners to rise round. It now prefers, among its passing tries, the one that laid what was asked. I haven’t done spirals on stacked floors from the generator yet, because the stacking leaves only 2 meters of rock between floors and a spiral sunk that deep would cut into it.

I also fixed a bug on the way: the tool that writes a sheet from a content file was silently dropping its floor heights.

Also done

  • A test for all of this, with 55 checks passing and none failing, plus 17 dungeon tests with none failing.
  • A 20-seed generator run with the option on: no failures, and every seed laid a turning stair and a spiral.
  • The designer page can place a spiral with the F key.

Still open: monsters don’t follow the party up a spiral between floors, and the shaft doesn’t get the theme’s bent wall pieces or meat yet.