I got 4 parts of a room with a pit. If you click a tile you build a part of the room. The effect i’d like is that the room takes shape the more tiles you add.
1 Corner part
1 Edge part
1 Bottom of the pit
1 normal floor tile
So let’s say we got this lay out:
000
000
000
Placing a tile in the center 0 would result in a regular pit_floor_tile. Now any tile adjacent to this tile will still be a regular pit_floor_tile.
That is until we make a square:
000
0PP
0PP
What this should do is create a square from 4 corner tiles.
_ _
| |
|_ _|
This would be the simple variation. More exotic configurations would include:
0PP
PPP
PPP
This would result in the center tile being a rotated corner tile. So would the top from this one and the tile on the left.
I’m using this code to scan tiles around a certain position:
for (int dx = -1; dx < 2; ++dx)
{
for (int dy = -1; dy < 2; ++dy) {
if (dx != 0 || dy != 0)
ScanTileAt(xPos + dx, yPos + dy);
}
}
My question is. Do i have the tile itself, PitTile, manage itself. As in i could pass it a copy of the map and have it calculate which model to show itself. This would require i dispatch info to all the tiles involved. Or should i keep this functionality in the Map class itself and have the tiles just be data containers?[/quote]
I would have the Map handle the Tiles, i.e., the Tiles never know anything about the Map.
Map would say “is this a 4x4?” and update the Tiles appropriately. This would result in much less code duplication / information sending, and faster and less buggy code (hopefully!)
Progressed on my code alot meanwhile, seperated alot of code into their own classes and moved alot of code to the more appropriate ones. However right now i’m stuck on scanning surrounding tiles. I can’t seem to find a decent algorhytm to do this.
0011
0111
0111
0111
I’d have to have the mapclass scan all the tiles i suppose. As i have it in my head right now, i figure i could scan the initial tile, do the loop, store any tiles that i encounter and are equal to the initial tile. Add them to a queue and then repeat the scan process till the queue is empty.
Although i’m not too sure how to implement this properly.
I would just scan each 9x9 and set their center tiles appropriately.
for x in tileXSize
for y in tileYSize
tileSurroundings = new int[3,3];
for offX in -1 to 1
for offY in -1 to 1
tileSurroundings[ offX+1, offY+1 ] = tiles[x+offX, y+offY];
}
}
tiles[x,y] = GetTileObjectFromSurroundings( tileSurroundings );
}
var tiles : GameObject[];
private var tileHash : Hashtable;
function Start() {
tileHash = new Hashtable();
add tiles to tileHash
}
function GTOFS( ts : whatever TileSurroundings is ) {
tilesIndex =
( ts[0,0] ? "1" : "0" ) +
( ts[1,0] ? "1" : "0" ) +
( ts[2,0] ? "1" : "0" ) +
( ts[1,1] ? "1" : "0" ) +
etc...
return Instantiate( tileHash[tilesIndex] );
}
Then in your start function you’d add each ‘tiles’ to ‘tileHash’ in a way that names them appropriately.
The piece for the center of
000
011
011
for example would be
tileHash.Add( “000011011”, tiles[indexOfThat] );