@@ -255,13 +255,13 @@ public void Update(ElapsedTime elapsedTime)
255
255
}
256
256
257
257
// Calculate all the distances to items we need to stop at (level crossings, other cars).
258
- var stopDistances = new List < float > ( ) ;
258
+ var stopDistance = float . MaxValue ;
259
259
for ( var crossing = NextCrossingIndex ; crossing < crossings . Count ; crossing ++ )
260
260
{
261
261
if ( crossings [ crossing ] . Item . CrossingGroup != null && crossings [ crossing ] . Item . CrossingGroup . HasTrain )
262
262
{
263
263
// TODO: Stopping distance for level crossings!
264
- stopDistances . Add ( crossings [ crossing ] . Distance - RoadCarSpawner . StopDistance ) ;
264
+ stopDistance = Math . Min ( stopDistance , crossings [ crossing ] . Distance - RoadCarSpawner . StopDistance ) ;
265
265
break ;
266
266
}
267
267
}
@@ -271,13 +271,13 @@ public void Update(ElapsedTime elapsedTime)
271
271
if ( spawnerIndex > 0 )
272
272
{
273
273
if ( ! cars [ spawnerIndex - 1 ] . CarriesCamera )
274
- stopDistances . Add ( cars [ spawnerIndex - 1 ] . Travelled - cars [ spawnerIndex - 1 ] . Length / 2 ) ;
274
+ stopDistance = Math . Min ( stopDistance , cars [ spawnerIndex - 1 ] . Travelled - cars [ spawnerIndex - 1 ] . Length / 2 ) ;
275
275
else
276
- stopDistances . Add ( cars [ spawnerIndex - 1 ] . Travelled - cars [ spawnerIndex - 1 ] . Length * 0.65f - 4 - cars [ spawnerIndex - 1 ] . Speed * 0.5f ) ;
277
- }
276
+ stopDistance = Math . Min ( stopDistance , cars [ spawnerIndex - 1 ] . Travelled - cars [ spawnerIndex - 1 ] . Length * 0.65f - 4 - cars [ spawnerIndex - 1 ] . Speed * 0.5f ) ;
277
+ }
278
278
279
279
// Calculate whether we're too close to the minimum stopping distance (and need to slow down) or going too slowly (and need to speed up).
280
- var stopDistance = stopDistances . Count > 0 ? stopDistances . Min ( ) - Travelled - Length / 2 : float . MaxValue ;
280
+ stopDistance = stopDistance - Travelled - Length / 2 ;
281
281
var slowingDistance = BrakingFactor * Length ;
282
282
if ( stopDistance < slowingDistance )
283
283
Speed = SpeedMax * ( float ) Math . Sin ( ( Math . PI / 2 ) * ( stopDistance / slowingDistance ) ) ;
0 commit comments