Esempio n. 1
0
    private void CreateCoin(BoardCellIndex cellIndex)
    {
        if (coinCreationParticlesPrefab != null && audioManager != null)
        {
            var position = CalculateGlobalCellCenter(cellIndex);
            var coin     = coinsPool.Instantiate(position);
            coin.transform.localScale = cellSize;

            if (IsLeftBorder(cellIndex))
            {
                coin.GetComponent <Rigidbody2D>().AddForce(Vector2.left * UnityEngine.Random.Range(5.0f, 25.0f), ForceMode2D.Impulse);
            }
            else if (IsRightBorder(cellIndex))
            {
                coin.GetComponent <Rigidbody2D>().AddForce(Vector2.right * UnityEngine.Random.Range(5.0f, 25.0f), ForceMode2D.Impulse);
            }
            else if (IsTopBorder(cellIndex))
            {
                coin.GetComponent <Rigidbody2D>().AddForce(Vector2.up * UnityEngine.Random.Range(15.0f, 25.0f), ForceMode2D.Impulse);
            }
            else // is bottom border
            {
                coin.GetComponent <Rigidbody2D>().AddForce(Vector2.down * UnityEngine.Random.Range(0.0f, 10.0f), ForceMode2D.Impulse);
            }

            var particles = Instantiate(coinCreationParticlesPrefab, position, Quaternion.identity);
            Destroy(particles, 0.5f);

            audioManager.CreateTemporaryAudioSource("CoinCreation");
        }
    }
Esempio n. 2
0
    private int CountAliveNeighborsOf(BoardCellIndex index)
    {
        var neighborsTypes = new BoardCellType[]
        {
            GetCellType(new BoardCellIndex(index.X - 1, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X - 1, index.Y)),
            GetCellType(new BoardCellIndex(index.X - 1, index.Y + 1)),
            GetCellType(new BoardCellIndex(index.X, index.Y + 1)),
            GetCellType(new BoardCellIndex(index.X, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y - 1)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y)),
            GetCellType(new BoardCellIndex(index.X + 1, index.Y + 1))
        };

        var aliveCount = 0;

        foreach (var nType in neighborsTypes)
        {
            if (nType == BoardCellType.Alive)
            {
                ++aliveCount;
            }
        }

        return(aliveCount);
    }
Esempio n. 3
0
 public bool IsBorder(BoardCellIndex cellIndex)
 {
     return(IsLeftBorder(cellIndex) ||
            IsRightBorder(cellIndex) ||
            IsBottomBorder(cellIndex) ||
            IsTopBorder(cellIndex));
 }
Esempio n. 4
0
 private bool IsValidCellIndex(BoardCellIndex index)
 {
     return(index.X >= 0 &&
            index.X < numberOfCells.x &&
            index.Y >= 0 &&
            index.Y < numberOfCells.y);
 }
Esempio n. 5
0
 private Vector3 CalculateLocalCellCenter(BoardCellIndex index)
 {
     return(boardOrigin
            + new Vector3(index.X * cellSize.x, index.Y * cellSize.y, 0)
            + new Vector3(cellSize.x / 2.0f, cellSize.y / 2.0f, 0.0f)
            + new Vector3(index.X * cellsSpacing, index.Y * cellsSpacing, 0.0f));
 }
Esempio n. 6
0
 private void ChangeCellType(BoardCellIndex index, BoardCellType newCellType)
 {
     if (IsValidCellIndex(index))
     {
         var cellIndex1d = ToIndex1D(index);
         var cell        = cells[cellIndex1d];
         ChangeCellType(cell, cellIndex1d, newCellType);
     }
 }
Esempio n. 7
0
 private Vector2[] GetNewUVs(BoardCellType newCellType, BoardCellIndex cellIndex)
 {
     if (IsBorder(cellIndex))
     {
         return(BoardCellUVsFactory.GetTransparentUVs());
     }
     else
     {
         return(BoardCellUVsFactory.GetUVsFor(newCellType));
     }
 }
Esempio n. 8
0
    public BoardCellIndex PickCell(Vector3 point)
    {
        var p = transform.InverseTransformPoint(point) - boardOrigin;

        var index = new BoardCellIndex(
            Mathf.FloorToInt(p.x / (cellSize.x + cellsSpacing)),
            Mathf.FloorToInt(p.y / (cellSize.y + cellsSpacing))
            );

        return(index);
    }
Esempio n. 9
0
    public override IEnumerable <MetaCell> GetCellsOn(IBoard board)
    {
        var cellsOrigin = board.PickCell(transform.position);

        var xSignal = transform.localScale.x < 0.0f ? -1 : 1;
        var ySignal = transform.localScale.y < 0.0f ? -1 : 1;

        foreach (var o in offsets)
        {
            var cellIndex = new BoardCellIndex(cellsOrigin.X + o.X * xSignal, cellsOrigin.Y + o.Y * ySignal);

            yield return(new MetaCell()
            {
                Index = cellIndex,
                Type = cellType
            });
        }
    }
Esempio n. 10
0
 private bool IsTopBorder(BoardCellIndex cellIndex)
 {
     return(cellIndex.Y == numberOfCells.y - 1);
 }
Esempio n. 11
0
 private bool IsBottomBorder(BoardCellIndex cellIndex)
 {
     return(cellIndex.Y == 0);
 }
Esempio n. 12
0
 private bool IsRightBorder(BoardCellIndex cellIndex)
 {
     return(cellIndex.X == numberOfCells.x - 1);
 }
Esempio n. 13
0
 private int ToIndex1D(BoardCellIndex index)
 {
     return(index.X * numberOfCells.y + index.Y);
 }
Esempio n. 14
0
 public Vector3 CalculateGlobalCellCenter(BoardCellIndex index)
 {
     return(transform.TransformPoint(CalculateLocalCellCenter(index)));
 }
Esempio n. 15
0
 private BoardCellType GetCellType(BoardCellIndex index)
 {
     return(IsValidCellIndex(index) ?
            cells[ToIndex1D(index)].Type : BoardCellType.Dead);
 }
Esempio n. 16
0
 private bool IsLeftBorder(BoardCellIndex cellIndex)
 {
     return(cellIndex.X == 0);
 }
Esempio n. 17
0
 public BoardCell(BoardCellIndex index)
 {
     Index = index;
 }