Пример #1
0
        public void Update(float turnRate)
        {
            // continuously adjust the car's forward direction and speed
            mTurnRate = turnRate;


            /// Two distinct states to be concerned with
            ///
            ///     1. There are next road segment to move towards
            ///     2. Within the bounds of current road segment
            ///
            if (mCurrentRoadSegment < mRoad.NumDefinedSegments())
            {
                Vector2 travelled = Center - mRoad.RoadSegmentStartPos(mCurrentRoadSegment);
                if (travelled.Length() >= mRoad.RoadSegmentLength(mCurrentRoadSegment))
                {
                    mCurrentRoadSegment++;
                    if (mCurrentRoadSegment >= mRoad.NumDefinedSegments())
                    {
                        ResetCarPosition();
                    }
                }
            }
            else
            {
                ResetCarPosition();
            }

            UpdateCarDirAndSpeed();
        }
Пример #2
0
        public bool Update(float ticksToTravel)
        {
            // continuously adjust the ball's forward direction and speed
            bool newState = false;

            /// distinct states to be concerned with
            ///
            ///     1. Has a valide next state (road segment)
            ///         1a. continues to be valid (within the bounds of road segment)
            ///         1b. if not, trasition to next state
            ///     2. No more valid next state: reset
            ///
            if (mCurrentRoadSegment < mRoad.NumDefinedSegments())
            {
                Vector2 travelled = Center - mRoad.RoadSegmentStartPos(mCurrentRoadSegment);
                if (travelled.Length() >= mRoad.RoadSegmentLength(mCurrentRoadSegment))
                {
                    mCurrentRoadSegment++;

                    newState = true;
                    if (mCurrentRoadSegment >= mRoad.NumDefinedSegments())
                    {
                        ResetBallPosition();
                    }
                }
            }
            else
            {
                ResetBallPosition();
                newState = true;
            }

// **** set dir and velocity only during state trasition ***
// CONSEQUENCE?: Last state/setment (under user control) may be
//                 wrong if user changes the state (Road Size/Dir)
//                 while we are in the segment
            if (newState ||
                (mCurrentRoadSegment == (mRoad.NumDefinedSegments() - 1))
                )
            {
                UpdateBallDirAndSpeed(ticksToTravel);
            }
// SOLUTION? Call UpdateBallDirAndSpeed() during _EVERY_ Update
//                 for LAST SEGMENT only.

            return(newState);
        }