Exemple #1
0
    public IEnumerator GenerateGroundLevel()
    {
        GenericBlockData dirt  = BlockServiceProvider.instance.GetBlock(2);
        GenericBlockData grass = BlockServiceProvider.instance.GetBlock(4);

        for (int x = 0; x < m_Size; x++)
        {
            for (int y = 0; y < m_Size; y++)
            {
                if (y < 10)
                {
                    Vector3  position = transform.position + new Vector3(x, y) * 1.5f;
                    BigBlock block    = Instantiate(m_Prefab, position, Quaternion.identity).GetComponent <BigBlock>();
                    if (y > 5)
                    {
                        if (y < 9)
                        {
                            //Dirt
                            block.Initialize(dirt);
                        }
                        else
                        {
                            //Grass
                            block.Initialize(grass);
                        }
                    }
                    block.UpdateBlock();
                    block.transform.parent = this.transform;

                    //m_Data[x, y] = block.DisableBlock(); ;
                }
            }
        }
        m_Done = true;
        yield return(new WaitForEndOfFrame());
    }
Exemple #2
0
    public IEnumerator PopulateCaves(byte[,] caveData)
    {
        byte[,] caves = caveData;
        Stack <Vector2> m_cachedCave = new Stack <Vector2>();

        for (int x = 0; x < m_Size; x++)
        {
            for (int y = 0; y < m_Size; y++)
            {
                if (caves[x, y] > 15)
                {
                    if (x - 1 > 0 && x + 1 < m_Size)
                    {
                        if (y - 1 > 0)
                        {
                            if (caves[x - 1, y] > 15 && caves[x + 1, y] > 15)
                            {
                                //Ground Check
                                if (caves[x - 1, y - 1] < 15 && caves[x, y - 1] < 15 && caves[x + 1, y - 1] < 15)
                                {
                                    for (int heightCheck = 0; heightCheck < 4;)
                                    {
                                        if (caves[x - 1, y + heightCheck] > 15 && caves[x, y + heightCheck] > 15 && caves[x + 1, y + heightCheck] > 15)
                                        {
                                            heightCheck++;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                        yield return(new WaitForEndOfFrame());

                                        if (y + heightCheck < m_Size)
                                        {
                                            Debug.Log(heightCheck);
                                            if (heightCheck == 4)
                                            {
                                                //GenerateStore (Test)

                                                int RandomStore = Random.Range(0, 2);

                                                if (RandomStore > 0)
                                                {
                                                    GenericBlockData dirt = BlockServiceProvider.instance.GetBlock(2);

                                                    Vector3 leftPosition   = transform.position + new Vector3(x - 1, y) * 1.5f;
                                                    Vector3 centerPosition = transform.position + new Vector3(x, y) * 1.5f;
                                                    Vector3 rightPosition  = transform.position + new Vector3(x + 1, y) * 1.5f;

                                                    BigBlock leftBlock   = Instantiate(m_Prefab, leftPosition, Quaternion.identity).GetComponent <BigBlock>();
                                                    BigBlock centerBlock = Instantiate(m_Prefab, centerPosition, Quaternion.identity).GetComponent <BigBlock>();
                                                    BigBlock rightBlock  = Instantiate(m_Prefab, rightPosition, Quaternion.identity).GetComponent <BigBlock>();

                                                    leftBlock.Initialize(dirt);
                                                    centerBlock.Initialize(dirt);
                                                    rightBlock.Initialize(dirt);

                                                    leftBlock.UpdateBlock();
                                                    centerBlock.UpdateBlock();
                                                    rightBlock.UpdateBlock();

                                                    if (RandomStore == 1)
                                                    {
                                                        Vector3 storePosition = transform.position + new Vector3(x, y + 1) * 1.5f;
                                                        Instantiate(m_Shop, storePosition, Quaternion.identity);
                                                    }

                                                    yield return(new WaitForEndOfFrame());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #3
0
 public void EnableBlock(BigBlockData data)
 {
     m_SmallBlocks      = data.smallBlocks;
     m_Data             = data.data;
     transform.position = data.position;
 }
Exemple #4
0
 public BigBlockData(SmallBlock[] smallBlocks, GenericBlockData data, Vector3 position)
 {
     m_SmallBlocks = smallBlocks;
     m_Data        = data;
     m_Position    = position;
 }
Exemple #5
0
 public void Initialize(GenericBlockData data)
 {
     m_Data = data;
 }