private IEnumerator ProcessAllNewGemsMovements (Action onFinished)
    {
        var gemsBoard = GemsManager.GetGemsBoard ();
        var width = gemsBoard.GetLength (0);
        var height = gemsBoard.GetLength (1);
        var gemsToMove = new List<Gem> (width * height);

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
                gemsToMove.Add (gemsBoard[x, y]);
        }

        while (gemsToMove.Count > 0)
        {
            for (int i = gemsToMove.Count - 1; i >= 0; i--)
            {
                if (!gemsToMove[i].ProcessMovement ())
                    gemsToMove.RemoveAt (i);
            }

            yield return null;
        }

        onFinished.Invoke ();
    }
Beispiel #2
0
    public bool ProcessMovement()
    {
        if (Mathf.Abs(TargetPosition.x - transform.position.x) > 0.1f)
        {
            transform.position = Vector2.Lerp(transform.position, new Vector2(TargetPosition.x, transform.position.y), 0.4f);
            isHorizontalMoving = true;
        }
        else if (isHorizontalMoving)
        {
            transform.position = new Vector2(TargetPosition.x, transform.position.y);
            GemsManager.GetGemsBoard()[Column, Row] = this;
            isHorizontalMoving = false;
        }

        if (Mathf.Abs(TargetPosition.y - transform.position.y) > 0.1f)
        {
            transform.position = Vector2.Lerp(transform.position, new Vector2(transform.position.x, TargetPosition.y), 0.4f);
            isVerticalMoving   = true;
        }
        else if (isVerticalMoving)
        {
            transform.position = new Vector2(transform.position.x, TargetPosition.y);
            GemsManager.GetGemsBoard()[Column, Row] = this;
            isVerticalMoving = false;
        }

        return(isHorizontalMoving || isVerticalMoving);
    }
    private Gem GetHorizontalNeighboar (Gem currentGem, int dir)
    {
        if (currentGem.Column + dir < 0 || currentGem.Column + dir >= gemsManager.BoardWidth)
            return null;

        var NeighboarGem = GemsManager.GetGemsBoard () [currentGem.Column + dir, currentGem.Row];
        if (NeighboarGem == null)
            return null;

        NeighboarGem.LastColumn = NeighboarGem.Column;
        NeighboarGem.Column -= dir;

        currentGem.LastColumn = currentGem.Column;
        currentGem.Column += dir;

        return NeighboarGem;
    }
    private Gem GetVerticalNeighboar (Gem currentGem, int dir)
    {
        if (currentGem.Row + dir < 0 || currentGem.Row + dir >= gemsManager.BoardHeight)
            return null;

        var NeighboarGem = GemsManager.GetGemsBoard () [currentGem.Column, currentGem.Row + dir];
        if (NeighboarGem == null)
            return null;

        NeighboarGem.LastRow = NeighboarGem.Row;
        NeighboarGem.Row -= dir;

        currentGem.LastRow = currentGem.Row;
        currentGem.Row += dir;

        return NeighboarGem;
    }
Beispiel #5
0
 public void UpdateGemBoard()
 {
     GemsManager.GetGemsBoard()[Column, Row] = this;
 }