//TODO - fcole - Data-drive this
 private int tileSetIndexForTile(LevelGenMap.TileType tile)
 {
     switch (tile)
     {
         default:
         case LevelGenMap.TileType.A:
             return 1;
         case LevelGenMap.TileType.B:
             return 0;
         case LevelGenMap.TileType.C:
             return 2;
         case LevelGenMap.TileType.D:
             return 3;
         case LevelGenMap.TileType.E:
             return 4;
         case LevelGenMap.TileType.F:
             return 5;
     }
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        LevelGenMap t = (LevelGenMap)target;

        if (t.Grid != null)
        {
            EditorGUILayout.IntField("Map Size", t.Grid.Length);
        }
        else
        {
            EditorGUILayout.IntField("Map Size", 0);
        }

        if (GUILayout.Button("Reset"))
        {
            t.Reset();
        }
    }
Beispiel #3
0
    private int countAliveNeighbours(LevelGenMap.TileType[,] map, int x, int y)
	{
		int count = 0;
		for (int i = -1; i < 2; ++i)
		{
			for (int j = -1; j < 2; ++j)
			{
				int neighbour_x = x + i;
				int neighbour_y = y + j;

				// If we're looking at the middle point
				if (i == 0 && j == 0)
					continue; // Do nothing, we don't want to add ourselves in!

				// In case the index we're looking at it off the edge of the map
				else if (neighbour_x < this.Bounds.IntXMin() || neighbour_y < this.Bounds.IntYMin() || neighbour_x >= this.Bounds.IntXMax() || neighbour_y >= this.Bounds.IntYMax())
					++count;

				// Otherwise, a normal check of the neighbour
				else if (map[neighbour_x, neighbour_y] == BASE_TYPE)
					++count;
			}
		}
		return count;
	}
Beispiel #4
0
    private void doSimulationStep(LevelGenMap.TileType[,] prevMap, LevelGenMap.TileType[,] newMap)
	{
		for (int x = this.Bounds.IntXMin(); x < this.Bounds.IntXMax(); ++x)
		{
			for (int y = this.Bounds.IntYMin(); y < this.Bounds.IntYMax(); ++y)
            {
                int inBoundsX = x - this.Bounds.IntXMin();
                int inBoundsY = y - this.Bounds.IntYMin();

                // Make sure this tile matches our valid tile types to run CA on
                if ((_originalMap[inBoundsX, inBoundsY] | this.ValidBaseTilesForGeneration) != this.ValidBaseTilesForGeneration)
                    continue;

				int nbs = countAliveNeighbours(prevMap, x, y);

				if (prevMap[x, y] == BASE_TYPE)
				{
					// First, if a cell is alive but has too few neighbours, kill it.
					newMap[inBoundsX, inBoundsY] = nbs < this.DeathLimit ? CAVE_TYPE : BASE_TYPE;
				}
				else
				{
					// Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born'
					newMap[inBoundsX, inBoundsY] = nbs > this.BirthLimit ? BASE_TYPE : CAVE_TYPE;
				}
			}
		}
	}
Beispiel #5
0
	private void tracePathBetweenCoordinates(LevelGenMap.Coordinate coord1, LevelGenMap.Coordinate coord2)
	{
        int modifier = 1;

        List<LevelGenMap.Coordinate> corridor = new List<LevelGenMap.Coordinate>();

        if (coord1.x != coord2.x)
        {
            int startX = coord1.x < coord2.x ? coord1.x + modifier : coord2.x + modifier;
            int endX = coord1.x < coord2.x ? coord2.x : coord1.x;

            for (int x = startX; x < endX; ++x)
            {
                fillCorridorTile(x, coord2.y, corridor);
            }

            modifier = 0;
        }

        if (coord1.y != coord2.y)
        {
            int startY = coord1.y < coord2.y ? coord1.y + modifier : coord2.y + modifier;
            int endY = coord1.y < coord2.y ? coord2.y + (1 - modifier) : coord1.y + (1 - modifier);

            for (int y = startY; y < endY; ++y)
            {
                fillCorridorTile(coord1.x, y, corridor);
            }
        }

        _corridorTiles.Add(corridor);
	}
Beispiel #6
0
 private bool isPositionFreeInArea(LevelGenMap.Coordinate position, int minDistance)
 {
     foreach (EnemySpawnGroup enemySpawn in _enemySpawns)
     {
         if (Vector2.Distance(position.integerVector, enemySpawn.Origin) < minDistance)
             return false;
     }
     return true;
 }