public double GetAcceleration(Car car, Car next, ITrack track) { var distance = track.Distance(car, next); if (distance < ComfortDistance) { _targetVelocity = next.Velocity / 2; } if (distance > ComfortDistance * 5) { _targetVelocity = _comfortVelocity; } var a = (_targetVelocity - car.Velocity); if (a > MaxAceleration) a = MaxAceleration; if (a < -MaxAceleration) a = -MaxAceleration; return a; }
public static double Distance(this ITrack track, Car a, Car b) { if (a.Position < b.Position) return b.Position - a.Position; return track.Length + b.Position - a.Position; }
private void CarOnPositionUpdated(Car car) { RaisePropertyChanged("X"); RaisePropertyChanged("Y"); RaisePropertyChanged("Angle"); }
public void Drive(Car next, ITrack track) { double a = _driver.GetAcceleration(this, next, track); _velocity += a; }
public CarViewModel(Track track, Car car) { _track = track; _car = car; _car.PositionUpdated += CarOnPositionUpdated; }