//Destroy the road and initially generate 10 pieces at the beginning public void Reset() { Segments.Clear(); for (int i = 0; i < 10; i++) { var piece = new RoadSegment(content, world, Size * (i - 1), Highlight); Segments.AddLast(piece); } }
public void Update(GameTime gameTime, float playerY) { //Destroy road segments which the player has passed, //and create a new one far ahead of the player if (playerY - Segments.First.Value.Y > Size * 2) { Segments.First.Value.Destroy(); Segments.RemoveFirst(); var piece = new RoadSegment(content, world, Segments.Last.Value.Y + Size, Highlight); Segments.AddLast(piece); } //Change the highlated lane double d = gameTime.TotalGameTime.TotalSeconds - HighlightChangeTime; if (d > highlightChangeInterval) { HighlightChangeTime = gameTime.TotalGameTime.TotalSeconds; Highlight = new Random().Next(4); } }