Beispiel #1
0
    IEnumerator GrowScoreBox(GrowData data)
    {
        float startY = data.box.transform.localScale.y;

        if (data.highScore == 0)
        {
            data.highScore++;
        }
        Vector3 endSize = new Vector3(data.box.transform.localScale.x, ((data.score / data.highScore) * maxHeight) + startY, data.box.transform.localScale.z);
        float   timer   = 0f;
        bool    growing = true;

        while (growing)
        {
            data.box.transform.localScale = Vector3.Lerp(data.box.transform.localScale, endSize, timer);
            data.scoreText.text           = (Mathf.Ceil(Mathf.Lerp(float.Parse(data.scoreText.text), data.score, timer))).ToString();
            if (timer > 1f)
            {
                growing             = false;
                data.scoreText.text = data.score.ToString();
            }
            if (winText.gameObject.activeSelf == false && timer > 0.35f)
            {
                winText.gameObject.SetActive(true);
                if (data.place == 0)
                {
                    winText.color = Color.yellow;
                    winText.text  = "Tie game!";
                }
                else if (data.place == 1)
                {
                    if (data.box == redBox)
                    {
                        winText.color = new Color(229f / 250f, 57 / 250f, 50 / 250f);
                        winText.text  = "Red wins!";
                    }
                    else if (data.box == greenBox)
                    {
                        winText.color = new Color(13 / 250f, 179 / 250f, 101 / 250f);
                        winText.text  = "Green wins!";
                    }
                }
            }
            timer += Time.deltaTime / growTime;
            yield return(null);
        }
    }
Beispiel #2
0
Datei: Oak.cs Projekt: heyx3/Elve
    public List<Vector2i> Grow(VoxelTypes[,] worldGrid, GrowData dataBase)
    {
        GrowData_Oak dat = (GrowData_Oak)dataBase;

        List<Vector2i> changed = new List<Vector2i>();

        //Clear out the current leaves.
        changed.Capacity += dat.Leaves.Count;
        for (int i = 0; i < dat.Leaves.Count; ++i)
        {
            worldGrid[dat.Leaves[i].x, dat.Leaves[i].y] = VoxelTypes.Empty;
            changed.Add(dat.Leaves[i]);
        }
        dat.Leaves.Clear();

        //Extend the tree-top upwards.
        Vector2i counter = new Vector2i(dat.SproutPos.x, dat.TopY);
        for (int i = 0; i < GrowthRate && counter.y < worldGrid.GetLength(1) - 1; ++i)
        {
            counter.y += 1;

            if (!WorldVoxels.IsTreeFodder(worldGrid[counter.x, counter.y]))
            {
                break;
            }

            worldGrid[counter.x, counter.y] = dat.TreeType;
            changed.Add(counter);
            dat.TopY = counter.y;
            dat.MaxBoundBox.y = UnityEngine.Mathf.Max(dat.MaxBoundBox.y, counter.y);
        }

        //Add leaves spreading out from the top.
        dat.LeavesRadius += 1;
        AddLeaves(dat, worldGrid);
        changed.Capacity += dat.Leaves.Count;
        changed.AddRange(dat.Leaves);

        return changed;
    }
Beispiel #3
0
 public Tree(IGrowPattern pattern, GrowData dat)
 {
     GrowPattern = pattern;
     GrowDat = dat;
 }
Beispiel #4
0
Datei: Oak.cs Projekt: heyx3/Elve
 public bool Occupies(GrowData baseData, Vector2i worldPos, bool includeLeaves)
 {
     //The logs occupy a single column of space.
     if (worldPos.x == baseData.SproutPos.x)
     {
         GrowData_Oak dat = (GrowData_Oak)baseData;
         if (worldPos.y >= dat.SproutPos.y && worldPos.y <= dat.TopY)
         {
             return true;
         }
         else
         {
             return includeLeaves && dat.Leaves.Any(le => (le == worldPos));
         }
     }
     else
     {
         return includeLeaves && ((GrowData_Oak)baseData).Leaves.Any(le => (le == worldPos));
     }
 }