Exemplo n.º 1
0
    private void Start()
    {
        cam          = Camera.main;
        Chunkcreator = GetComponentInParent <Chunkcreator>();

        if (right == true)
        {
            if (top == true)
            {
                ID = 6;
            }
            else if (bottom == true)
            {
                ID = 5;
            }
            else
            {
                ID = 1;
            }
        }
        else if (left == true)
        {
            if (top == true)
            {
                ID = 7;
            }
            else if (bottom == true)
            {
                ID = 4;
            }
            else
            {
                ID = 3;
            }
        }
        else if (bottom == true)
        {
            ID = 0;
        }
        else if (top == true)
        {
            ID = 2;
        }
    }
Exemplo n.º 2
0
    //Spawn new Chunk
    public void setNewChunk(int iD)
    {
        if (GetComponentInParent <World_Manager>().Spawn == true)
        {
            GetComponentInParent <World_Manager>().Spawn = false;
            if (iD == 0)
            {
                if (thisChunk.Spawns[1] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y - Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY - 1;
                    thisChunk.Spawns[1]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 1)
            {
                if (thisChunk.Spawns[4] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x + Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();

                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX + 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[4]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 2)
            {
                if (thisChunk.Spawns[6] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y + Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY + 1;
                    thisChunk.Spawns[6]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 3)
            {
                if (thisChunk.Spawns[3] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x - Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX - 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[3]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 4)
            {
                if (thisChunk.Spawns[0] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x - Chunksize * Tilesize, transform.position.y - Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX - 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY - 1;
                    thisChunk.Spawns[0]        = true;
                }
                if (thisChunk.Spawns[3] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x - Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX - 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[3]        = true;
                }
                if (thisChunk.Spawns[1] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y - Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY - 1;
                    thisChunk.Spawns[1]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 5)
            {
                if (thisChunk.Spawns[2] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x + Chunksize * Tilesize, transform.position.y - Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX + 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY - 1;
                    thisChunk.Spawns[2]        = true;
                }
                if (thisChunk.Spawns[1] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y - Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY - 1;
                    thisChunk.Spawns[1]        = true;
                }
                if (thisChunk.Spawns[4] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x + Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX + 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[4]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 6)
            {
                if (thisChunk.Spawns[7] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x + Chunksize * Tilesize, transform.position.y + Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX + 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY + 1;
                    thisChunk.Spawns[7]        = true;
                }
                if (thisChunk.Spawns[4] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x + Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX + 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[4]        = true;
                }
                if (thisChunk.Spawns[6] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y + Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY + 1;
                    thisChunk.Spawns[6]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
            else if (iD == 7)
            {
                if (thisChunk.Spawns[5] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x - Chunksize * Tilesize, transform.position.y + Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX - 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY + 1;
                    thisChunk.Spawns[5]        = true;
                }
                if (thisChunk.Spawns[6] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x, transform.position.y + Chunksize * Tilesize), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY + 1;
                    thisChunk.Spawns[6]        = true;
                }
                if (thisChunk.Spawns[3] == false)
                {
                    Chunkcreator save = Instantiate <GameObject>(startChunkGO, new Vector2(transform.position.x - Chunksize * Tilesize, transform.position.y), Quaternion.identity, transform.parent).GetComponent <Chunkcreator>();
                    save.thisChunk.WorldSpaceX = thisChunk.WorldSpaceX - 1;
                    save.thisChunk.WorldSpaceY = thisChunk.WorldSpaceY;
                    thisChunk.Spawns[3]        = true;
                }
                else
                {
                    GetComponentInParent <World_Manager>().Spawn = true;
                }
            }
        }
    }
Exemplo n.º 3
0
    public bool[] AddChunk(Chunk achunk, Chunkcreator chunkcreator)
    {
        int placeX;
        int placeY;

        bool[] returner = new bool[8];
        int    counter  = 0;

        if (achunk.WorldSpaceX < 0)
        {
            placeX = 100 - (Mathf.Abs(achunk.WorldSpaceX) % 100);
        }
        else
        {
            placeX = achunk.WorldSpaceX % 100;
        }

        if (achunk.WorldSpaceY < 0)
        {
            placeY = 100 - (Mathf.Abs(achunk.WorldSpaceY) % 100);
        }
        else
        {
            placeY = achunk.WorldSpaceY % 100;
        }

        world[placeX, placeY]        = achunk;
        worldSkripts[placeX, placeY] = chunkcreator;

        if (placeX > 0 && placeY > 0)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1 && i == 1)
                    {
                    }
                    else
                    {
                        if (worldSkripts[((placeX - 1) + j) % 100, ((placeY - 1) + i) % 100] != null)
                        {
                            returner[counter] = true;
                            worldSkripts[((placeX - 1) + j) % 100, ((placeY - 1) + i) % 100].setSpawn(7 - counter);
                            Debug.Log(7 - counter);
                            counter += 1;
                        }
                        else
                        {
                            counter += 1;
                        }
                    }
                }
            }
        }

        else if (placeX <= 0 && placeY <= 0)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1 && i == 1)
                    {
                    }
                    else
                    {
                        if (worldSkripts[(100 - (Mathf.Abs(placeX - 1) % 100) + j) % 100, (100 - (Mathf.Abs(placeY - 1) % 100) + i) % 100] != null)
                        {
                            returner[counter] = true;
                            worldSkripts[(100 - (Mathf.Abs(placeX - 1) % 100) + j) % 100, (100 - (Mathf.Abs(placeY - 1) % 100) + i) % 100].setSpawn(7 - counter);
                            Debug.Log(7 - counter);
                            counter += 1;
                        }
                        else
                        {
                            counter += 1;
                        }
                    }
                }
            }
        }

        else if (placeX <= 0)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1 && i == 1)
                    {
                    }
                    else
                    {
                        if (worldSkripts[(100 - (Mathf.Abs(placeX - 1) % 100) + j) % 100, ((placeY - 1) + i) % 100] != null)
                        {
                            returner[counter] = true;
                            worldSkripts[(100 - (Mathf.Abs(placeX - 1) % 100) + j) % 100, ((placeY - 1) + i) % 100].setSpawn(7 - counter);

                            Debug.Log(7 - counter);
                            counter += 1;
                        }
                        else
                        {
                            counter += 1;
                        }
                    }
                }
            }
        }

        else if (placeY <= 0)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (j == 1 && i == 1)
                    {
                    }
                    else
                    {
                        if (worldSkripts [((placeX - 1) + j) % 100, (100 - (Mathf.Abs(placeY - 1) % 100) + i) % 100] != null)
                        {
                            returner[counter] = true;
                            worldSkripts[((placeX - 1) + j) % 100, (100 - (Mathf.Abs(placeY - 1) % 100) + i) % 100].setSpawn(7 - counter);
                            Debug.Log(7 - counter);
                            counter += 1;
                        }
                        else
                        {
                            counter += 1;
                        }
                    }
                }
            }
        }
        Spawn = true;
        return(returner);
    }