Ejemplo n.º 1
0
        public override void Update(GameTime GameTime)
        {
            GameObject nearestBall = control.nearestObj;
            Ship       ship        = Game1.controlShip;
            Vector2    deltaPos    = nearestBall.position - ship.position;
            Vector2    targetPos   = nearestBall.position;

            float dotVelocity = 0.0f;

            Vector2.Dot(ref ship.currentVelocity, ref nearestBall.currentVelocity, out dotVelocity);

            float tempDot = 0.0f;

            Vector2.Dot(ref deltaPos, ref ship.currentVelocity, out tempDot);
            if ((tempDot < 0) || (dotVelocity > -0.93))//magic number == about 21 degrees
            {
                Vector2 shipVel  = ship.currentVelocity;
                Vector2 tempVect = Vector2.Zero;
                if (tempVect != Vector2.Zero)
                {
                    tempVect = Vector2.Normalize(shipVel) * control.maxSpeed;
                }
                shipVel = tempVect;
                float combinedSpeed  = ((deltaPos * control.maxSpeed) + nearestBall.currentVelocity).Length();
                float predictionTime = deltaPos.Length() / combinedSpeed;
                targetPos = nearestBall.position + (nearestBall.currentVelocity * predictionTime);
                deltaPos  = (targetPos - ship.position) * 0.02f; //Number makes sure the movement is made at proper speed.
            }

            ship.ChangeDirection(deltaPos * activation);
        }
Ejemplo n.º 2
0
        public override void Update(GameTime GameTime)
        {
            GameObject asteroid = control.nearestObj;
            Ship       ship     = Game1.controlShip;
            Vector2    vecBrake = (ship.position - asteroid.position) * 0.02f; //Number makes sure the movement is made at proper speed.


            ship.ChangeDirection(vecBrake * activation);
        }