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"); } }
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); }
public bool IsBorder(BoardCellIndex cellIndex) { return(IsLeftBorder(cellIndex) || IsRightBorder(cellIndex) || IsBottomBorder(cellIndex) || IsTopBorder(cellIndex)); }
private bool IsValidCellIndex(BoardCellIndex index) { return(index.X >= 0 && index.X < numberOfCells.x && index.Y >= 0 && index.Y < numberOfCells.y); }
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)); }
private void ChangeCellType(BoardCellIndex index, BoardCellType newCellType) { if (IsValidCellIndex(index)) { var cellIndex1d = ToIndex1D(index); var cell = cells[cellIndex1d]; ChangeCellType(cell, cellIndex1d, newCellType); } }
private Vector2[] GetNewUVs(BoardCellType newCellType, BoardCellIndex cellIndex) { if (IsBorder(cellIndex)) { return(BoardCellUVsFactory.GetTransparentUVs()); } else { return(BoardCellUVsFactory.GetUVsFor(newCellType)); } }
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); }
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 }); } }
private bool IsTopBorder(BoardCellIndex cellIndex) { return(cellIndex.Y == numberOfCells.y - 1); }
private bool IsBottomBorder(BoardCellIndex cellIndex) { return(cellIndex.Y == 0); }
private bool IsRightBorder(BoardCellIndex cellIndex) { return(cellIndex.X == numberOfCells.x - 1); }
private int ToIndex1D(BoardCellIndex index) { return(index.X * numberOfCells.y + index.Y); }
public Vector3 CalculateGlobalCellCenter(BoardCellIndex index) { return(transform.TransformPoint(CalculateLocalCellCenter(index))); }
private BoardCellType GetCellType(BoardCellIndex index) { return(IsValidCellIndex(index) ? cells[ToIndex1D(index)].Type : BoardCellType.Dead); }
private bool IsLeftBorder(BoardCellIndex cellIndex) { return(cellIndex.X == 0); }
public BoardCell(BoardCellIndex index) { Index = index; }