# Game Jam Procedural Generation Part III

In the last episode of Game Jam Procedural Generation I talked a lot about generating the base of the platforming level in Starforger II, and carving out rooms into the ground of the level.

So now we have a basic level that with a bunch of empty rooms below the ground. The next step is going to be connecting those rooms together. To do this I built a quick class called a TunnelSnake (tunnel snakes rule) to dig tunnels from any point on the map to any other point. Here's the full source of that class:

So now we have a basic level that with a bunch of empty rooms below the ground. The next step is going to be connecting those rooms together. To do this I built a quick class called a TunnelSnake (tunnel snakes rule) to dig tunnels from any point on the map to any other point. Here's the full source of that class:

class TunnelSnake {

public int X;

public int Y;

public int Width = 1;

public int Height = 2;

public int EndX;

public int EndY;

int verticalSteps;

int verticalStepMax = 4;

int forceHorizontal = 0;

int forceHDirection = 1;

public TunnelSnake(int x, int y, int endX, int endY) {

X = x;

Y = y;

EndX = endX;

EndY = endY;

}

public void Dig(GridCollider grid) {

while (X != EndX || Y != EndY) {

grid.SetRect(X, Y, Width, Height, false);

if (Rand.Chance(50) || forceHorizontal > 0) {

if (forceHorizontal > 0) {

X += forceHDirection;

Height = 2;

X = (int)Util.Clamp(X, 2, grid.TileColumns - 2);

}

else {

X += Math.Sign(EndX - X);

}

forceHorizontal--;

if (forceHorizontal == 0) {

verticalSteps = 0;

}

}

else {

verticalSteps++;

Y += Math.Sign(EndY - Y);

if (verticalSteps == verticalStepMax) {

forceHorizontal = Rand.Int(3, 15);

forceHDirection = Rand.Sign;

}

}

if (Rand.Chance(50)) {

if (Rand.Chance(50)) {

Width += Rand.Sign;

Width = (int)Util.Clamp(Width, 1, 5);

}

if (Rand.Chance(50)) {

Height += Rand.Sign;

Height = (int)Util.Clamp(Height, 2, 6);

}

}

}

}

}

No Comments