Esempio n. 1
0
        public void UpdatePosition()
        {
            shots.UpdatePosition(game.BounceBack, game.SunLocation,
                                 game.InverseGravity, game.Gravity);

            if ((state != ShipState.Normal) &&
                (state != ShipState.HyperCharge))
            {
                return;
            }

            position += velocity;

            // Check the game boundaries.  If bounce back mode is enabled,
            // reverse the velocity when we reach the edge
            if (game.BounceBack)
            {
                if (position.X > screenBounds.Right || position.X < screenBounds.Left)
                {
                    velocity.X = -velocity.X;
                }
                if (position.Y > screenBounds.Bottom || position.Y < screenBounds.Top)
                {
                    velocity.Y = -velocity.Y;
                }
            }
            else
            {
                if (position.X > screenBounds.Right)
                {
                    position.X = screenBounds.Left;
                }

                if (position.X < screenBounds.Left)
                {
                    position.X = screenBounds.Right;
                }

                if (position.Y > screenBounds.Bottom)
                {
                    position.Y = screenBounds.Top;
                }

                if (position.Y < screenBounds.Top)
                {
                    position.Y = screenBounds.Bottom;
                }
            }


            // update velocity due to the gravity of the sun...
            Point   sunLocation = game.SunLocation;
            Vector2 gravity     = new Vector2(sunLocation.X - position.X, sunLocation.Y - position.Y);
            float   length      = Vector2.Length(gravity);

            gravity = Vector2.Normalize(gravity);
            gravity = (gravity * game.Gravity) * (1.0f / (length * length));

            if (game.InverseGravity)
            {
                velocity -= gravity;
            }
            else
            {
                velocity += gravity;
            }

            if (length < Constants.SunCollisionLimit)
            {
                SetState(ShipState.Dying);
                game.SendPointToAllPlayers();
            }
        }