Esempio n. 1
0
File: Chunk.cs Progetto: KNGKAI/snow
 public static void AddModifier(ChunkModifier modifier)
 {
     Modifiers.Add(modifier);
 }
Esempio n. 2
0
    private static IEnumerator GenerateLevelProccess()
    {
        ChunkModifier m;
        Vector2Int    a;
        Vector2Int    b;
        Vector3       position;
        int           r;

        playing   = 0;
        levelTime = 0;

        r = CurrentLevel.Radius;
        loadingProcces      = 0;
        loadingProccesLimit = ((int)CurrentLevel.Path.Lenght / r) + CurrentLevel.Path.Nodes.Count;

        animatedLevelPreview = CurrentLevel.Preview;
        for (int x = 0; x < animatedLevelPreview.width; x++)
        {
            for (int y = 0; y < animatedLevelPreview.height; y++)
            {
                animatedLevelPreview.SetPixel(x, y, Color.white);
            }
        }
        animatedLevelPreview.Apply();

        Chunk.Destroy();
        Waypoint.Destroy();

        //SetupModifiers()
        a = CurrentLevel.Path.Nodes[0];
        b = Vector2Int.zero;
        for (int i = 0; i < CurrentLevel.Path.Nodes.Count; i++)
        {
            if (CurrentLevel.Path.Nodes[i].x < a.x)
            {
                a.x = CurrentLevel.Path.Nodes[i].x;
            }
            if (CurrentLevel.Path.Nodes[i].x > b.x)
            {
                b.x = CurrentLevel.Path.Nodes[i].x;
            }
            if (CurrentLevel.Path.Nodes[i].y > b.y)
            {
                b.y = CurrentLevel.Path.Nodes[i].y;
            }
        }

        a -= Vector2Int.one * CurrentLevel.Radius * 2;
        b += Vector2Int.one * CurrentLevel.Radius * 2;

        m = new ChunkModifier(a, (int)Mathf.Max(b.x - a.x, b.y - a.y));
        m.DrawLevelPath(CurrentLevel, 4);
        yield return(null);

        loadingProcces++;

        Chunk.ClearModifiers();
        Chunk.AddModifier(m);

        //GenerateChunks()
        for (int i = 1; i < CurrentLevel.Path.Lenght; i += r)
        {
            position = (Vector2)CurrentLevel.Path.Evaluate(i);
            for (int x = -r; x <= r; x += r)
            {
                for (int y = -r; y <= r; y += r)
                {
                    Chunk.Update(position.x + x, position.y + y, 2);
                }
            }

            for (int j = 0; j < r; j++)
            {
                CurrentLevel.Path.Paint(ref animatedLevelPreview, j + i);
            }
            yield return(null);

            loadingProcces++;
        }

        //PlaceWaypoints()
        for (int i = 2; i < CurrentLevel.Path.Nodes.Count; i++)
        {
            position   = (Vector2)CurrentLevel.Path.Nodes[i];
            position.z = position.y;
            position.y = Terrain.GetSlope(position.z);

            Waypoint.Create(position, CurrentLevel.Radius * 2);
            yield return(null);

            loadingProcces++;
        }

        Player.transform.position = Vector3.forward;
        Player.transform.rotation = Quaternion.LookRotation(Vector3.forward);

        Camera.transform.position = Vector3.up;

        yield return(null);

        loadingProcces++;

        playing   = 1;
        levelTime = 0;
    }