Dungeon game

Hi,

I’ve created a randomly generated dungeon - rooms are interlinked via corridors, scrolling is 8-way. Using LibGdx to render the ‘cruddy’ gfx.

The rooms at the moment are just carved out of the map as can be seen in this link : https://sites.google.com/site/dungeonplanetlite/home (the green is the whole map zoomed out)

Rooms are stored in a dynamic structure but no real information about them - was wondering what would be best way to store rooms and to have designs in them (tables, bricks etc)?

My map is stored in a 2d array of type Tiles:


	Tile[][] tilesArray = new Tile[(MyGdxGame.AMOUNTSCREENSX * MyGdxGame.SCREENWIDTH)/MyGdxGame.TILEWIDTH]
					       [(MyGdxGame.AMOUNTSCREENSY * MyGdxGame.SCREENHEIGHT)/MyGdxGame.TILEHEIGHT];


and Tile is:


abstract class AbstractTile {
	protected String name;   // type of tile - corridor for instance, wall
	protected float x, y;
	protected boolean visible;

	protected Texture texture;

	abstract void loadTexture();
}

class Tile extends AbstractTile {
	public Tile(String name) {
		this.name = name;
		visible = true;
	}
}

Loop to draw the map:


	public void drawMap(SpriteBatch batch, Texture img, Texture corridorImg,
			float width, float height) {

		int camX = (int) camera.position.x - MyGdxGame.SCREENWIDTH / 2;
		camX /= MyGdxGame.TILEWIDTH;
		int endX = MyGdxGame.SCREENWIDTH / MyGdxGame.TILEWIDTH + camX;

		int camY = (int) camera.position.y - MyGdxGame.SCREENHEIGHT / 2;
		camY /= MyGdxGame.TILEHEIGHT;
		int endY = MyGdxGame.SCREENHEIGHT / MyGdxGame.TILEHEIGHT + camY;

		if (!MyGdxGame.bDebug) {

			// Optimized loop - we only draw what we can see, that is just one
			// screen
			for (int y = camY; y < endY + 1; y++) {
				for (int x = camX; x < endX + 1; x++) {
					if (tilesArray[x][y].visible) {
						// batch.setColor(1, 0, 0, 1);

						batch.draw(img, tilesArray[x][y].x, tilesArray[x][y].y,
								width, height);
					} else {
						// this a corridor - horrible way of doing this, needs
						// to change!
						if (tilesArray[x][y].name.contains("orridor")) {
							batch.draw(corridorImg, tilesArray[x][y].x,
									tilesArray[x][y].y, width, height);
						}
					}
				}
			}
		} else {  // draw the whole map! Only used when debug is turned on
			for (int y = 0; y < MyGdxGame.ROWS; y++) {
				for (int x = 0; x < MyGdxGame.COLS; x++) {
					if (tilesArray[x][y].visible) {
						// batch.setColor(1, 0, 0, 1);
						batch.draw(img, tilesArray[x][y].x, tilesArray[x][y].y,
								width, height);
					}
				}
			}

		}
	}


If visible is false, a tile is not drawn - this is what makes up a room.

I need a way of now drawing rooms where the invisible tiles are, any good advice on this? I was thinking of having another structure which had the room positions, width, height
and the type of room it is.

Thanks,
Steve

My understanding is each “room” occupies an empty area in your tile array. I would recommend a room object structure like you specified, and store the rooms in a List (or gdx Array). You could have a Room abstract class with a render() method and other methods if need be, and for each room type you could have a child class of Room. When you are going to render the scene, just iterate through the room list and call its render method. You shouldn’t need to modify your tile rendering code too much because tiles and rooms are independant of each other.

This isn’t related to your room problem, but more of a suggestion for your tile structure:
If you’re going to have tiles that have no real extra data stored inside them (ex: a wall, a brick, a torch, etc.), you could have a singleton class with a list of all the “normal” tiles in the game. Then rather than having to create a new Tile object for every single tilespace in your world, you could share one instance of a tile. Dungeons have a lot of floors, so a new object for every single tile becomes very memory-heavy.

Sorry if that is confusing, if you need me to clarify I can.