vendredi 8 novembre 2019

How to generate rooms and connections between them from the set room list (given room sizes) on the 2D table?

I'm trying to implement a dungeon generator in my small Java project (text roguelike - moving from start to exit with random events on the map) but there is one problem - I'm just starting with Java and I don't know a lot about "proper" coding, thus having problems with the generating the map; map is a 2D array (ex. 50x50 tiles) where you move your character between rooms connected with multiple corridors.

I was considering a few options how to make it:

  • make a list of set rooms which then they would appear in the specific places on the array (dividing 50x50 array to 5x5 tiles and then from the first 4x4 tile choose one point there would be the left upper corner of the room - the smallest room I want to make 2x2)
  • to generate the map by going each column while generating a few playable tiles and the next column would add another playable tiles next to the existing ones + after a few iterations making corridors but it sounds more complicated
  • making corridors by checking if 2 tiles (that are rooms) are on the same level (vertical or horizontal) and then swapping tiles from "wall" to "playable" ones (it's a text game so from "#" to ".")

Does it sound viable or should I look for some other solution? Or is it too complicated/nearly impossible and there is a way simpler way of doing it?

# # # # # # #
# # . . . # #
# # . # . E #
# # . . . # #
# # . # . # #
# H . . . # #
# # # # # # #

"H" is a hero, "E" is exit, "#" are walls and "." playable tiles (where you can move by an input - up/down/left/right)




Aucun commentaire:

Enregistrer un commentaire