コード例 #1
0
ファイル: Map.cs プロジェクト: bigstupidx/gameWaveRush
    private void GetIntegerMaps()
    {
        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                // process terrainMap
                int id = 0;
                if (Mathf.RoundToInt(terrainMap.GetPixel(x, y).r) == 1)
                {
                    id = 1;
                    openCells.Add(new Vector2(x, y));                           // add to a list of empty cells
                }
                terrain [y, x] = id;
                // process collidersMap
                colliders [y, x] = (int)collidersMap.GetPixel(x, y).a;
                // process objectsMap
                if (Random.value < objectsMap.GetPixel(x, y).a)
                {
                    CreateRandomObject(x, y);
                }
            }
        }

        int[,] temp = new int[size, size];
        Int2DArrayUtil.CopyArray(terrain, temp);
        for (int x = 0; x < size; x++)
        {
            for (int y = 0; y < size; y++)
            {
                if (temp[y, x] == 1)
                {
                    int sum = SumNeighbors(temp, x, y, 0);
                    if (sum > 1)
                    {
                        terrain [y, x] = sum;
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: Map.cs プロジェクト: bigstupidx/gameWaveRush
    private int SumNeighbors(int[,] arr, int x, int y, int id)
    {
        int sum = 0;

        if (Int2DArrayUtil.IsInBounds(arr, x, y + 1) && arr [y + 1, x] == id)
        {
            sum += 1;
        }
        if (Int2DArrayUtil.IsInBounds(arr, x + 1, y) && arr [y, x + 1] == id)
        {
            sum += 2;
        }
        if (Int2DArrayUtil.IsInBounds(arr, x, y - 1) && arr [y - 1, x] == id)
        {
            sum += 4;
        }
        if (Int2DArrayUtil.IsInBounds(arr, x - 1, y) && arr [y, x - 1] == id)
        {
            sum += 8;
        }

        return(sum + 1);
    }