Exemple #1
0
    public void Merge(GraphicEntity1 another, float duration = 0)
    {
        // TODO race condition!!
        var target = rect.Merge(another.rect);

        another.Remove(duration);
        Transform(target, duration);
    }
Exemple #2
0
    GraphicEntity1 AddRectAtPosition(int minX, int minY, int width, int height, Color color)
    {
        GridRect emptyRect = new GridRect(minX, minY, width, height);

        if (emptyRect != null)
        {
            var ge = GraphicEntity1.New(emptyRect, board);
            ge.SetColor(color);
            ge.SetOpacity(1, Beat(1));
            return(ge);
        }
        return(null);
    }
Exemple #3
0
    public IList <GraphicEntity1> BreakToUnitSquares(float duration = 0)
    {
        var squares = new List <GraphicEntity1>();

        foreach (var gridRect in rect.SplitToUnitSquares())
        {
            var g = GraphicEntity1.New(gridRect, board);
            g.SetColor(animatable.color);
            squares.Add(g);
        }
        Remove(duration, DONTUNLOCK: true);
        return(squares);
        // splits existing x to this as much as it can
    }
Exemple #4
0
    GraphicEntity1 AddRect(int width, int height, Color color, bool allowStacking = false)
    {
        GridRect emptyRect = board.FindEmptyRectWithSize(width, height);

        if (emptyRect == null && allowStacking)
        {
            emptyRect = board.FindRandomRectWithSize(width, height);
        }
        if (emptyRect != null)
        {
            var ge = GraphicEntity1.New(emptyRect, board);
            ge.SetColor(color);
            //ge.SetOpacity(opacity, Beat(1));
            return(ge);
        }
        return(null);
    }
Exemple #5
0
 /*** ACCESS ***/
 public void LockTiles(GridRect rect, GraphicEntity1 ge)
 {
     //Debug.Log($"Board1: Lock {rect}");
     for (int x = rect.min.x; x <= rect.max.x; x++)
     {
         for (int y = rect.min.y; y <= rect.max.y; y++)
         {
             if (x >= 0 && x < width && y >= 0 && y < height)
             {
                 graphicEntities[x, y] = ge;
             }
             else
             {
                 //Debug.Log($"lock failed {x} {y}");
             }
         }
     }
 }
Exemple #6
0
    bool AddRow(Color color, bool force = false)
    {
        // search for vacant spots
        // MUTEX
        Debug.Log("StoryOfASound: Looking for empty row");
        GridRect emptyRow = board.FindEmptyRow();

        Debug.Log("Found empty row" + emptyRow);
        if (emptyRow == null)
        {
            emptyRow = new GridRect(0, Random.Range(0, rows), cols, 1);
            foreach (var ge in board.GraphicEntities())
            {
                ge.DeleteRect(emptyRow, Beat(1));
            }
        }

        var newGe = GraphicEntity1.New(emptyRow, board);

        newGe.SetColor(color);
        //newGe.SetOpacity(1, Beat(1));
        return(true);
    }
Exemple #7
0
    IEnumerator Section4Lifecycle(GraphicEntity1 g)
    {
        var targetRect = new GridRect(g.rect.min.x - 1, g.rect.min.y - 1, Random.Range(1, 5), Random.Range(1, 4));

        g.Transform(targetRect, Beat(1));
        if (targetRect.area > 1)
        {
            g.SetOpacity(Mathf.Max(0, g.opacity - 0.17f), Beat(1));
        }
        yield return(Rest(0, 1.25f));

        if (g.opacity.IsZero())
        {
            g.Remove();
            yield break;
        }
        // Break to unit squares
        g.RotateTo(0, Beat(1));
        yield return(Rest(0, 2f));

        var squares = g.BreakToUnitSquares();

        yield return(Rest(0, 1.25f));

        var rot = Random.Range(0, 12) * 30;

        foreach (var unit in squares)
        {
            var colorRand = Random.value;
            if (colorRand < 0.45f)
            {
                unit.SetColor(orange.WithAlpha(unit.opacity));
            }
            //else if (colorRand < 0.66f) {
            //unit.SetColor(blue.WithAlpha(unit.opacity));
            //}
            int dx = Random.Range(-1, 2);
            int dy = Random.Range(-1, 2);
            unit.Move(dx, dy, Beat(1.25f));
            unit.RotateFor(rot, Beat(2));
        }
        yield return(Rest(0, 2.5f));

        rot = Random.Range(0, 12) * 30;
        foreach (var unit in squares)
        {
            int dx = Random.Range(-1, 2);
            int dy = Random.Range(-1, 2);
            unit.Move(dx, dy, Beat(1));
            unit.RotateFor(rot, Beat(2));
        }
        yield return(Rest(0, 2.5f));

        foreach (var unit in squares)
        {
            if (unit != null)
            {
                if (Random.value < 0.2f)
                {
                    StartCoroutine(Section4Lifecycle(unit));
                }
                else
                {
                    unit.Remove(Beat(2));
                }
            }
        }
    }
Exemple #8
0
    void AddSquareAtPosition(int x, int y, Color color)
    {
        var ge = GraphicEntity1.New(new GridRect(x, y, 1, 1), board);

        ge.SetColor(color);
    }