This is what my tile map looks like (red highlighting added for clarity):
My code:
private List<List<int>> _layoutLayer = new List<List<int>>(50); // Layout Layer
private List<List<int>> _trLayer = new List<List<int>>(50); // Transitional Layer
private List<List<int>> _entityLayer = new List<List<int>>(50); // Object Layer
private List<List<int>> _logicLayer = new List<List<int>>(50); // Logic Layer
// To add a tile
if (inputManager.IsMouseHeld(true))
{
try
{
switch (_currentLayer)
{
case LayerRepresentation.LayoutLayer:
_layoutLayer[_gridMouseY][_gridMouseX] = _currentTile;
break;
case LayerRepresentation.TransitionalLayer:
_trLayer[_gridMouseY][_gridMouseX] = _currentTile;
break;
case LayerRepresentation.EntityLayer:
_entityLayer[_gridMouseY][_gridMouseX] = _currentTile;
break;
case LayerRepresentation.LogicLayer:
_logicLayer[_gridMouseY][_gridMouseX] = _currentTile;
break;
}
}
catch
{
// Player clicked outside of map bounds, add specified amount of tiles to map
}
}
What I need:
When the player clicks outside of map bounds for example on the point A, add the amount of tiles between point A and the map to the map's height. Do the same with point B, but add to the map width instead.
What I've tried:
// Inside the above catch block
if (_mapHeight - _gridMouseY == 0 && _gridMouseX < _mapWidth && _gridMouseX > -1)
{
List<int> tempDefaultLayout = new List<int>();
List<int> tempDefaultOther = new List<int>();
for (int i = 0; i < _layoutLayer[0].Count; i++)
{
tempDefaultLayout.Add(0);
tempDefaultOther.Add(-1);
}
_layoutLayer.Insert(_gridMouseY, tempDefaultLayout);
_trLayer.Insert(_gridMouseY, tempDefaultOther);
_entityLayer.Insert(_gridMouseY, tempDefaultOther);
_logicLayer.Insert(_gridMouseY, tempDefaultOther);
_mapHeight++;
}
else if (_mapWidth - _gridMouseX == 0 && _gridMouseY < _mapHeight && _gridMouseY > -1)
{
for (int y = 0; y < _layoutLayer.Count; y++)
{
for (int x = 0; x < _layoutLayer[y].Count; x++)
{
if (_layoutLayer[y].Count <= _mapWidth)
{
_layoutLayer[y].Add(0);
_trLayer[y].Add(-1);
_entityLayer[y].Add(-1);
_logicLayer[y].Add(-1);
}
}
}
_mapWidth++;
}
return;
The problems:
The first part is about adding tiles to the height (only one row at a time) Adding the temp
List
s to the layerList
s withList.Add()
doesn't work, I don't know why. I usedList.Insert
instead.The second part is used to add a single column to the map one at a time.
Any help would be appreciated.