Пример #1
0
    public void HandleCollision(float point)
    {
        switch (objectType)
        {
        case 0:
            sp.AddSnowAtPoint(point);
            break;

        case 1:
            sb.Grow();
            break;
        }
    }
Пример #2
0
    public void AddSnowAtPoint(float x)
    {
        int i = Mathf.RoundToInt((x - leftBorder.position.x) / cellSize);

        // Debug.Log(i);
        if (i < 0)
        {
            i = 0;
        }
        if (i >= sizeX)
        {
            i = sizeX - 1;
        }
        points[i]++;
        bool     leftFree  = false;
        bool     rightFree = false;
        SnowPile pile      = null;

        if (i > 0)
        {
            if (points[i] > points[i - 1] + 1)
            {
                leftFree = true;
            }
        }
        else
        {
            points[i]--;
            return;
            // pile = FindAnotherPile(leftBorder.position.x - cellSize);
            // if(pile != null)
            // {
            //  if( baseY + cellSize * points[0] - pile.GetHeightAtPoint(leftBorder.position.x - cellSize) > cellSize)
            //  {
            //      leftFree = false;
            //  }
            //  // else
            //  // {

            //  // }
            // }
        }

        if (i < sizeX - 1)
        {
            if (points[i] > points[i + 1] + 1)
            {
                rightFree = true;
            }
        }
        else
        {
            points[i]--;
            return;
            // pile = FindAnotherPile(rightBorder.position.x + cellSize);
            // if(pile != null)
            // {
            //  if( baseY + cellSize * points[0] - pile.GetHeightAtPoint(rightBorder.position.x + cellSize) > cellSize)
            //  {
            //      rightFree = false;
            //  }
            //  // else
            //  // {

            //  // }
            // }
        }

        if (leftFree && rightFree)
        {
            if (Random.value > 0.5f)
            {
                leftFree = false;
            }
            else
            {
                rightFree = false;
            }
        }

        if (leftFree)
        {
            if (i > 0)
            {
                AddSnowAtPoint(x - cellSize);
                points[i]--;
            }
            else
            {
                if (pile != null)
                {
                    pile.AddSnowAtPoint(x - cellSize);
                    points[i]--;
                }
            }
            return;
        }

        if (rightFree)
        {
            if (i > 0)
            {
                AddSnowAtPoint(x + cellSize);
                points[i]--;
            }
            else
            {
                if (pile != null)
                {
                    pile.AddSnowAtPoint(x + cellSize);
                    points[i]--;
                }
            }
            return;
        }
        if (points[i] > currentHeight)
        {
            texture.Resize(sizeX, points[i] + 1);
            sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0, 0), pixelDens);
            spriteRenderer.sprite = sprite;
            for (int j = 0; j < sizeX; j++)
            {
                for (int k = 0; k < points[i] + 1; k++)
                {
                    if (k <= points[j] - 1)
                    {
                        texture.SetPixel(j, k, Color.white);
                    }
                    else
                    {
                        texture.SetPixel(j, k, Color.clear);
                    }
                }
            }
            currentHeight = points[i] + 1;
        }
        texture.SetPixel(i, points[i] - 1, Color.white);
        texture.Apply();
    }