Mythics
Mythics

Reputation: 803

How can I remove the extra tiles in this grid?

I'm working on a tile-based 2D game and having a minor issue with the map generation.

The general concept is that it creates one room by default and then builds off of any existing rooms until X number of rooms have been built or Y number of tries have failed.

The issue I'm coming into is probably simple and I just can't wrap my mind around it, but how would I go about removing the circled tiles? Each map generated is procedural, so I won't know exactly when spots like the circled ones show up and I can easily spot them with my eyes... I just can't think of an all encompassing way to handle them AFTER the map is already generated.

The goal is to never have walls doubled up where they aren't needed to be. I am not wanting to change the way the map is generated, but rather modify it after the fact. I also do not want to lose corners of rooms or similar.

I really feel like what I'm trying to do would have a name in image editing or similar, but that's certainly not my forte.

Described Image

Upvotes: 1

Views: 366

Answers (2)

Joshua Mee
Joshua Mee

Reputation: 602

I'd comment instead of answer if I could, as I can't I'll give an answer a go.

How're you storing the details of the level? You seem to want to know where two horizontal or two vertical walls are touching and delete them as long as they aren't corners.

It seems like you need a rule or two like...

if it's a horizontal wall and there is a tile either side, delete any above or below.

if it's a vertical wall and there is a tile above and below, delete any to the left or right

Upvotes: 1

Jack
Jack

Reputation: 133659

Your circled items are ambiguous because in certain situation you could remove the one circled by you or the otherside without breaking the rules (no mixing rooms neither open to external black tiles).

In any case I should think a little bit more about it but they just seem the tile that after being removed don't join two rooms neither have any adjacent (diagonal included) black tile.

I guess you could assign to every room a number and then remove any tile that:

  • doesn't connect two floor tiles with different numbers
  • neither have ajacent black blocks

Maybe you could do it also without numbering rooms but you will have to understand if all neighbours are from the same room or not by exploiting side adjacency.

Upvotes: 1

Related Questions