IEnumerator GoDownCoroutine(Ball ball) { CorridorType corridorType = CorridorType.Down; Vector3 lastPointInPath = _corridorsConductor.GetLastPointInPath(corridorType); int indexOfPoint = 0; while (lastPointInPath != ball.transform.position) { while (_corridorsConductor.IsPointOccupied(indexOfPoint, corridorType)) { yield return(new WaitForSeconds(0.2f)); } if (indexOfPoint > 0) { int prevPoint = indexOfPoint - 1; _corridorsConductor.SetOccupiedPointInPath(prevPoint, false, corridorType); } _corridorsConductor.SetOccupiedPointInPath(indexOfPoint, true, corridorType); Vector3 targetPoint = _corridorsConductor.GetPointPosition(indexOfPoint, corridorType); while (ball.transform.position != targetPoint) { ball.transform.position = gameStart ? Vector3.MoveTowards(ball.transform.position, targetPoint, (speedDownCorridor - _speedDownOffset) * Time.smoothDeltaTime) : Vector3.MoveTowards(ball.transform.position, targetPoint, speedDownCorridor * Time.smoothDeltaTime); yield return(new WaitForEndOfFrame()); } indexOfPoint++; } _ballToThrow = ball; }
public Parameters(int minNumRooms, int minRoomWidth, int minRoomHeight, CorridorType type) { MinNumRooms = minNumRooms; MinRoomWidth = minRoomWidth; MinRoomHeight = minRoomHeight; CorridorType = type; }
public void SetOccupiedPointInPath(int pointIndex, bool value, CorridorType type) { if (_occupiedPoints[type].Count - 1 < pointIndex) { Debug.LogWarning("To large pointIndex value."); return; } _occupiedPoints[type][pointIndex] = value; }
public Vector3 GetPointPosition(int pointIndex, CorridorType type) { if (_positionsOfCorridorPoints[type].Length - 1 < pointIndex) { Debug.LogWarning("Index out of points corridor path."); return(Vector3.zero); } return(_positionsOfCorridorPoints[type][pointIndex]); }
public bool IsPointOccupied(int pointIndex, CorridorType type) { if (_occupiedPoints[type].Count - 1 < pointIndex) { Debug.LogWarning("Index out of path."); return(false); } return(_occupiedPoints[type][pointIndex]); }
private void InitCorridorPath(GameObject pathContainer, CorridorType corridorType) { //check on correct count Transform[] pointsInCorridorPath = pathContainer.GetComponentsInChildren <Transform>().Skip(1).ToArray(); _positionsOfCorridorPoints.Add(corridorType, new Vector3[pointsInCorridorPath.Length]); _occupiedPoints.Add(corridorType, new Dictionary <int, bool>()); for (int i = 0; i < _positionsOfCorridorPoints[corridorType].Length; i++) { _positionsOfCorridorPoints[corridorType][i] = pointsInCorridorPath[i].transform.position; _occupiedPoints[corridorType].Add(i, false); } }
IEnumerator GoUpCoroutine(Ball ball) { CorridorType corridorType = CorridorType.Up; Vector3 lastPointInPath = _corridorsConductor.GetLastPointInPath(corridorType); float localSpeed = speedUpCorridor; int indexOfPoint = 0; while (lastPointInPath != ball.transform.position) { Vector3 targetPoint = _corridorsConductor.GetPointPosition(indexOfPoint, corridorType); while (ball.transform.position != targetPoint) { ball.transform.position = Vector3.MoveTowards(ball.transform.position, targetPoint, localSpeed * Time.smoothDeltaTime); localSpeed += upAcceleration; yield return(new WaitForEndOfFrame()); } indexOfPoint++; } ThrowBall(ball, Quaternion.Euler(0, 0, 60), impulseForce: 5f); }
public bool NextTo(Vector2Int vec, CorridorType type = CorridorType.Ortho, T val = default(T)) { if ((type == CorridorType.Ortho) || (type == CorridorType.Both)) { foreach (var p in ortho) { if (this[vec + p].Equals(val)) { return(true); } } } if ((type == CorridorType.Diago) || (type == CorridorType.Both)) { foreach (var p in diago) { if (this[vec + p].Equals(val)) { return(true); } } } return(false); }
public Vector3 GetLastPointInPath(CorridorType type) { int pathLength = _positionsOfCorridorPoints[type].Length; return(_positionsOfCorridorPoints[type][pathLength - 1]); }
public int GetPathLength(CorridorType type) { return(_positionsOfCorridorPoints[type].Length); }
public CorridorGenerator(Grid grid, CorridorType type) { m_grid = grid; m_type = type; }
public void setType(CorridorType newType) { corridorType = newType; }