Summer Project: Week 2 and 3

I was going to write a post last week, but a) ended up forgetting about it, and b) felt that I didn’t really have enough to write about. The previous week was  a quite unproductive week, due to visiting my parents.

Anyway, the task scheduled for these weeks was generating and connecting rooms to each other. I had some idea of the rules I wanted to handle this, but no real idea of how to actually implement it. I ended up looking through the articles on RogueBasin, and found an article on basic BSP-generated levels. In short, it splits the world into smaller leaves, and then splits those leaves, and so on, until the desired number of splits has been done.

Each of these leaves then had to contain a room (at this point, basically just a black square). Then I had to connect these rooms together. Since I’m not keeping track of which leaf got split from which, I can’t connect the rooms that way, like suggested in the article. Instead, I had to come up with another solution. What I ended up doing was:

  1. Pick a wall of the room
  2. Pick a spot on that wall
  3. Make a box from that position to the screen edge (for example, if top wall was picked, make a box between the top wall and the top edge of the screen)
  4. Check if that box collides with any other room, and store them
  5. Go through the stored rooms, and decide which one is closest to the original room
  6. Connect those rooms

A video of some tests can be found here.

This actually caused less of a performance hit than I was expecting. However, it came with some other drawbacks:

  • There’s no guarantee that a room actually gets connected another room
    • I do have an idea of how I might solve that (basically keep throwing out boxes until there are enough connections (the number of which is randomized when the room is created))
  • The room connections might not always be logical
    • For example, one room in the furthest right-hand side of the world might connect to a room on the furthest left-hand side of the world, despite there being other rooms “in the way” that should be more logical to connect.

So why did I do it this way? Well, I was getting frustrated trying to figure out a “better” way of doing it, and remembered raycasts in 3D graphics, so I wanted to try to emulate something like that. It ended up (mostly) working the way I wanted it, with just those two quirks.

What’s up next then? Well, after fixing the quirks, it’s time to add some gameplay. Probably something simple, like a special room to “go down a floor” and randomize the floor again, and after that, stats and loot, and last, fights. After that, I’m mostly done with the original project, and free to add whatever I feel like I want to add.

The code for this can be found on Git, more specifically in the FloorManager, Leaf and Room-classes.