public void AddSegment(RoadSegment segment) { _segments.Add(segment); }
private void GenerateRoad() { _roadParams = new RoadParameters { MaxHeight = 900, MaxCurve = 400, Length = 12, NumberOfZones = 12, Curvy = 0.8, Mountiany = 0.8, NumberOfSegmentsPerZone = 250, RoadSegmentSize = 5, NumberOfSegmentsPerColor = 4, OffRoadOffset = 130, }; _roadParams.Length = _roadParams.NumberOfZones * _roadParams.NumberOfSegmentsPerZone; _road = new List <RoadSegment>(); _roadZones = new List <RoadZone>(); HeightState currentStateHeight = HeightState.Flat; CurveState currentStateCurve = CurveState.Straight; var currentHeight = 0.0; var currentCurve = 0.0; var zones = _roadParams.NumberOfZones; while (zones-- > 0) { var zone = new RoadZone(_roadParams.NumberOfSegmentsPerZone); // Generate current zone var finalHeight = 0.0; switch (currentStateHeight) { case HeightState.Flat: { finalHeight = 0.0; break; } case HeightState.Up: { finalHeight = _roadParams.MaxHeight * _random.NextDouble(); break; } case HeightState.Down: { finalHeight = -_roadParams.MaxHeight * _random.NextDouble(); break; } } var finalCurve = 0.0; switch (currentStateCurve) { case CurveState.Straight: { finalCurve = 0.0; break; } case CurveState.Left: { finalCurve = -_roadParams.MaxCurve * _random.NextDouble(); break; } case CurveState.Right: { finalCurve = _roadParams.MaxCurve * _random.NextDouble(); break; } } zone.AddCurve(currentStateCurve, currentCurve, finalCurve); zone.AddHeight(currentStateHeight, currentHeight, finalHeight); for (int i = 0; i < _roadParams.NumberOfSegmentsPerZone; i++) { var segment = new RoadSegment { Height = zone.StartHeight + (zone.HeightStep * i), Curve = zone.StartCurve + (zone.CurveStep * i), SegmentSprite = SelectSegmentSprite(i) }; _road.Add(segment); zone.AddSegment(segment); } currentHeight = finalHeight; currentCurve = finalCurve; currentStateHeight = SelectNextZoneHeightTransition(); currentStateCurve = SelectNextZoneCurveTransition(); _roadZones.Add(zone); } }