Hello all,
this is a little hard to describe, so please bear with me. I’m writing a levelcreating class for an engine. It has to be flexible, but I want it to do alot of work. It’s a tile-based editor, and it takes 2 2d-Arrays (foreground, background) and a classList array.
The foreGround Array could look like this:
var foreGround:Array = new Array(
new Array(0, 0, 0, 0, 1, 1, 0),
new Array(0, 0, 0, 1, 1, 0, 0),
new Array(2, 0, 1, 1, 0, 0, 0),
new Array(0, 0, 0, 0, 0, 0, 1),
new Array(0, 0, 0, 0, 0, 1, 1),
new Array(1, 1, 1, 1, 1, 1, 1));
Here every 1 would represent the classList[0] class reference, which would be Dirt, in this case. 2 would represent the classList[1] reference, which in this case is Player.
This all works flawlessly, but the problem is when I try to be a bit more creative. The background objects will be buildings, that I want to be different each time. They’ll have rules, but are generated randomly. If a tile touches the ground, it has a chance to be a door, etc. This is still not a problem, the leveleditor simply checks the horizontal and vertical adjecent nodes from the array, and if they are the same number, it means they are the same ‘group of objects’, so to speak. If it is not, an ‘edge’ tile comes here.
The problem comes when I try to make a group of this object. I want all 3’s in that arrays that touch horizontally and vertically, to be a group of objects. Each object would hold a reference to this object, and that group object keeps info on how many windows this group has, how many doors, cracks, etc.
The simple thing to do is to check the tiles above it, and to the right of it. If they are 3, take their group object as yours. However, now look at this example:
var backGround:Array = new Array(
new Array(0, 0, 3, 3),
new Array(3, 3, 3, 3));
How would the lower left ‘3’ know that it’s connected to the rest? Would this involve pathfinding?
Thanks in advance for reading this far. If I wasn’t clear enough, please let me know and I’ll try to explain it better.
- Maqrkk