private void CreateDot(DotGridCoords coords) { var dot = Instantiate(dotPrefab).GetComponent <Dot>(); dot.name = "dot_" + coords.xPos + "_" + coords.yPos; dot.transform.parent = transform; dot.SetCoords(coords);; dotsInGrid.Add(dot); }
private Vector2 GetPositionForCoordinates(DotGridCoords coords) { var adjustedDotSize = (GameData.DOT_SPRITE_SIZE / dotPPU) + spacing; var worldPosition = Vector2.zero; // Set to "zero position" (bottom left dot position) worldPosition.x = -adjustedDotSize * ((columns - 1) / 2f); worldPosition.y = -adjustedDotSize * ((rows - 1) / 2f); // Add offset from zero position via dot coordinate worldPosition.x += adjustedDotSize * coords.yPos; worldPosition.y += adjustedDotSize * coords.xPos; return(worldPosition); }
/// <summary> /// Check dot in connections and remove it all have the same type /// </summary> private void CheckSelectedDots() { var currConnectionSystem = GameController.Instance.dotConnectionController; var connections = currConnectionSystem.GetConnections(); //if no connection or exactly one dot if (connections == null) { return; } if (connections.Count < 2) { currConnectionSystem.ClearConnections(); } var dotsNeedToRemovedInColumn = new byte[columns]; // if connection is square, mark all dots of the same type if (currConnectionSystem.IsLoopConnection()) { currConnectionSystem.ClearConnections(); foreach (var dot in dotsInGrid) { if (dot.GetDotType() == currConnectionSystem.GetConnectionType()) { connections.Add(dot); } } } GameController.Instance.UpdateScore(connections.Count); // mark all dots in connection foreach (var dot in connections) { dotsNeedToRemovedInColumn[dot.GetCoords().yPos]++; dot.ClearDotType(); // Clear dot status } // update position in all dots of all columns (if needs) for (byte i = 0; i < columns; i++) { if (dotsNeedToRemovedInColumn[i] == 0) { continue; } ExecuteDotOperation(i, (dot) => { if (dot.GetCoords().xPos != 0 && dot.GetDotType() != DotColorType.Clear) { var fallDist = GetBlankDotsUnderneath(dot); var newCoords = new DotGridCoords((byte)(dot.GetCoords().xPos - fallDist), i); dot.SetCoords(newCoords); dot.MoveToPosition(GetPositionForCoordinates(dot.GetCoords()), 0f); } }); } // for each column, recycle dots for (byte i = 0; i < columns; i++) { var removedCount = dotsNeedToRemovedInColumn[i]; for (byte j = 0; j < removedCount; j++) { // The lowest empty row var row = (byte)(rows - (removedCount - j)); var lastDotIndex = connections.Count - 1; var dot = connections[lastDotIndex]; connections.RemoveAt(lastDotIndex); dot.SetCoords(new DotGridCoords(row, i)); dot.Spawn(GetPositionForCoordinates(dot.GetCoords()), 0f); } } // clear connections currConnectionSystem.ClearConnections(); }
public void SetCoords(DotGridCoords coords) { _coords = coords; }