Exemplo n.º 1
0
    public void EnteredNewTemplate(TilemapTemplate template)
    {
        if (template.type == TilemapTemplate.TemplateType.Transition && activeLayer != 0)
        {
            StartCoroutine(Player.Instance.TransitionColors(Player.Instance.LayerColors[activeLayer + 1]));
            StartCoroutine(Manager.Instance.ChangeMusic(Manager.Instance.LayerClips[activeLayer + 1]));
        }

        playerIsInLevel++;

        if (playerIsInLevel > 2)
        {
            Destroy(ActiveGame[0]);
            ActiveGame.RemoveAt(0);
        }

        if (playing && currentGeneratedLevel >= levelsPerLayer)
        {
            winning = true;
            currentGeneratedLevel = 0;
        }
        currentGeneratedLevel++;

        Generate();
        if (activeLayer == 4 && !winning)
        {
            Generate();
            Generate();
        }
    }
Exemplo n.º 2
0
    public void Generate()
    {
        List <GameObject> TemplateList = Templates[activeLayer];

        TilemapTemplate last = ActiveGame.Count != 0 ? ActiveGame[ActiveGame.Count - 1].GetComponent <TilemapTemplate>() : null;

        Vector3 targetPosition = Vector3.zero;
        int     randomIndex    = 0;

        // If we can, generate a template that comes next from our tile.
        if (last != null)
        {
            targetPosition = new Vector3(last.transform.position.x, last.transform.position.y - templatesHeightDifference, last.transform.position.z);

            // THIS IS THE END
            if (winning && last.WinIndex == -1)
            {
                // We're doing this to test specific layers
                if (startLayer != -1)
                {
                    activeLayer = startLayer;
                    startLayer  = -1;
                }
                else
                {
                    activeLayer++;
                }

                winning = false;
                currentGeneratedLevel = 0;
                TemplateList          = Templates[activeLayer];
            }

            if (winning)
            {
                randomIndex = last.WinIndex;
            }
            else if (last.NextDependencies.Count != 0)
            {
                randomIndex = last.NextDependencies[Random.Range(0, last.NextDependencies.Count)];
            }
        }
        // If not, generate a template that can stand alone.
        else
        {
            randomIndex = Random.Range(0, TemplateList.FindAll(template => template.GetComponent <TilemapTemplate>().PrevDependencies.Count == 0).Count);
        }

        GameObject toSpawn = TemplateList[randomIndex];

        GameObject newTemplate = Instantiate(
            toSpawn,
            targetPosition,
            Quaternion.identity,
            this.transform
            );

        newTemplate.name = TemplateList[randomIndex].name;

        ActiveGame.Add(newTemplate);
    }