DriverGame/DriverGame/Car.cs
/// <summary>
/// Update the cars state based on the elapsed time
/// </summary>
/// <param name="elapsedTime">Amount of time that has elapsed</param>
Update the cars state based on the elapsed time
Update the cars state based on the elapsed time
public void Update(float elapsedTime)
        {
            if (movingLeft)
            {
                carLocation += (carSpeed * elapsedTime);
                if (carLocation >= DriverGame.RoadLocationLeft)
                {
                    movingLeft = false;
                    carLocation = DriverGame.RoadLocationLeft;
                }
            }
            if (movingRight)
            {
                carLocation -= (carSpeed * elapsedTime);
                if (carLocation <= DriverGame.RoadLocationRight)
                {
                    movingRight = false;
                    carLocation = DriverGame.RoadLocationRight;
                }
            }
        }
public void Update ( float elapsedTime ) { if ( movingLeft ) { carLocation += ( carSpeed * elapsedTime ) ; if ( carLocation >= DriverGame . RoadLocationLeft ) { movingLeft = false ; carLocation = DriverGame . RoadLocationLeft ; } } if ( movingRight ) { carLocation -= ( carSpeed * elapsedTime ) ; if ( carLocation <= DriverGame . RoadLocationRight ) { movingRight = false ; carLocation = DriverGame . RoadLocationRight ; } } }
Update the cars state based on the elapsed time
Update the cars state based on the elapsed time
// Move the car // Is the car all the way to the left? // Move the car // Is the car all the way to the right?
elapsedTime
float
Amount of time that has elapsed
Amount of time that has elapsed