Пример #1
0
    public Transform openatrandom()
    {
        locationscd randloc = mixedavailablelocations.Dequeue();

        mixedavailablelocations.Enqueue(randloc);
        return(sectoronlevel[randloc.x, randloc.y]);
    }
Пример #2
0
    public locationscd atrandomloc()
    {
        locationscd randloc = mixedlocations.Dequeue();

        mixedlocations.Enqueue(randloc);
        return(randloc);
    }
Пример #3
0
    public void LevelCreation()
    {
        sectoronlevel = new Transform[(int)gridscale.x, (int)gridscale.y];


        if (transform.Find(fulllevel))
        {
            DestroyImmediate(transform.Find(fulllevel).gameObject);
        }

        thefullloc = new List <locationscd>();
        for (int xaxis = 0; xaxis < gridscale.x; xaxis++)
        {
            for (int yaxis = 0; yaxis < gridscale.y; yaxis++)
            {
                thefullloc.Add(new locationscd(xaxis, yaxis));
            }
        }


        mixedlocations = new Queue <locationscd>(Shuffling.Fisher(thefullloc.ToArray(), index));

        playerspawnpoint = new locationscd((int)gridscale.x / 2, (int)gridscale.y / 2);



        Transform thecompleted = new GameObject(fulllevel).transform;

        thecompleted.parent = transform;

        for (int xaxis = 0; xaxis < gridscale.x; xaxis++)
        {
            for (int yaxis = 0; yaxis < gridscale.y; yaxis++)
            {
                Vector3   SectionLocation = locationtopos(xaxis, yaxis);
                Transform thegridsection  = Instantiate(prefgrid, SectionLocation, Quaternion.Euler(Vector3.right * 90)) as Transform;
                thegridsection.parent       = thecompleted;
                thegridsection.localScale   = Vector3.one * (1 - borders);
                sectoronlevel[xaxis, yaxis] = thegridsection;
            }
        }

        bool[,] hurdlelocations = new bool[(int)gridscale.x, (int)gridscale.y];
        int numberofhurdle = (int)(gridscale.x * gridscale.y * hurdlepercent);
        int howmany        = 0;
        List <locationscd> everyavailable = new List <locationscd> (thefullloc);

        for (int check = 0; check < numberofhurdle; check++)
        {
            randomh = Random.Range(0, 2);
            for (int i = 0; i < 3; i++)
            {
                if (randomh == i)
                {
                    hurdlepref = hurdles[i];
                }
            }
            locationscd rndlocation = atrandomloc();
            hurdlelocations[rndlocation.x, rndlocation.y] = true;
            howmany++;

            if (rndlocation != playerspawnpoint)
            {
                Vector3   hurdleloc = locationtopos(rndlocation.x, rndlocation.y);
                Transform newhurdle = Instantiate(hurdlepref, hurdleloc + Vector3.up * 0.50f, Quaternion.identity) as Transform;
                newhurdle.parent = thecompleted;

                everyavailable.Remove(rndlocation);
            }

            else
            {
                hurdlelocations[rndlocation.x, rndlocation.y] = false;
                howmany--;
            }
        }

        mixedavailablelocations = new Queue <locationscd>(Shuffling.Fisher(everyavailable.ToArray(), index));
    }