public void GenerateBlock(LinkedList <IDescriptorWithID> list) { if (_isNextCar) { if (_isBufferListDirty) { list.Clear(); foreach (var e in _bufferList) { list.AddLast(e); } _bufferList.Clear(); _isBufferListDirty = false; } float tmp1, tmp2, tmp3; tmp1 = _ss.TimeWindow; tmp2 = _ss.MinCarSpeed; tmp3 = _ss.MaxCarSpeed; _ss.TimeWindow = _timeWindow; _ss.MinCarSpeed = _minCarSpeed; _ss.MaxCarSpeed = _maxCarSpeed; _blockGen.GenerateBlock(list); _ss.TimeWindow = tmp1; _ss.MinCarSpeed = tmp2; _ss.MaxCarSpeed = tmp3; if (!_isFirstWallSet && _setFirstWall) { _isFirstWallSet = true; _wallBuffer = new WallDescriptor( new Vector2(_ss.Road.MiddlePosition, ((CarDescriptor)list.Last.Value).Position.y + _wallLen), _wallLen); list.AddLast(_wallBuffer); } ++_i; _isNextCar = false; } else { list.Clear(); } if (_isNextWall) { _wallBuffer.Position.y += _wallLen + _gapLen; list.AddLast(_wallBuffer); _isNextWall = false; } }
public void Reset() { _blockGen.Reset(); _wallLen = Random.Range(_wallLenMin, _wallLenMax); _gapLen = Random.Range(_gapLenMin, _gapLenMax); _count = Random.Range(_minCount, _maxCount + 1); _bufferList.Clear(); _isFirstWallSet = _setFirstWall = false; _isBufferListDirty = false; _wallBuffer = null; _i = 0; _timeWindow = (_wallLen + _gapLen) * 2 / _ss.NormalCarSpeed; _timeWindow = _timeWindow > _ss.TimeWindow ? _timeWindow : _ss.TimeWindow; }
/// <summary> /// Returns the correct rotation for the given horizonzal rotations. /// </summary> /// <returns></returns> public void CalculateRotationForHorizontalCorner(HorzDirection actual = HorzDirection.NotSet, HorzDirection next = HorzDirection.NotSet) { WallDescriptor wallToUse = null; var wall1 = ActualCreatedLevelBlock.transform.GetComponentsInChildren <WallDescriptor>().Where(wl => wl.WallNumber == 0).First(); var wall2 = ActualCreatedLevelBlock.transform.GetComponentsInChildren <WallDescriptor>().Where(wl => wl.WallNumber == 1).First(); actual = actual == HorzDirection.NotSet ? ActualHorizontalDirection : actual; next = next == HorzDirection.NotSet ? NextHorizontalDirection : next; if (actual == HorzDirection.Backwards) { wallToUse = next == HorzDirection.Left ? wall2 : wall1; } else if (actual == HorzDirection.Right) { wallToUse = next == HorzDirection.Backwards ? wall2 : wall1; } else if (actual == HorzDirection.Forward) { wallToUse = next == HorzDirection.Right ? wall2 : wall1; } else if (actual == HorzDirection.Left) { wallToUse = next == HorzDirection.Forward ? wall2 : wall1; } wallToUse.RotateWallFacesDirection(next); }
/// <summary> /// Checks if the both Wall Descriptors are opposite of each other. /// </summary> /// <param name="descriptorA"></param> /// <param name="descriptorB"></param> public bool IsOppositeWall(WallDescriptor descriptorA, WallDescriptor descriptorB) { return(Math.Abs(descriptorA.WallNumber - descriptorB.WallNumber) == 2 || Math.Abs(descriptorA.WallNumber - descriptorB.WallNumber) == 0); }