GetPosition() public method

public GetPosition ( ) : Vector2
return Vector2
Exemplo n.º 1
0
        /// <summary>
        /// Updates the Photon's position and graphics state
        /// </summary>
        /// <param name="elapsedTime">The time elapsed between the previous and current frame</param>
        public override void Update(float elapsedTime)
        {
            //Get the vector to the player
            toPlayer = player.GetPosition() - this.position;

            //determine how to chase the player
            if (homing)
            {
                //Photon 1st fired and if player is far away
                if (toPlayer.LengthSquared() > 3000)
                {
                    //chase the player
                    toPlayer.Normalize();
                    this.position += toPlayer * elapsedTime * this.velocity;
                }
                else //Become a dummy and go straight
                {
                    homing             = false;
                    lastPlayerPosition = toPlayer;
                }
            }
            else //When near the player
            {
                lastPlayerPosition.Normalize();
                this.position += elapsedTime * lastPlayerPosition * this.velocity;
            }

            //Update the Photon graphics state
            UpdatePhotonState(elapsedTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new bullet that will travel towards the Player's current position.
        /// </summary>
        /// <param name="id">Id for the bullet.</param>
        /// <param name="content">ContentManager to load content with.</param>
        /// <param name="position">Starting position for the bullet.</param>
        public ToPlayerBullet(uint id, ContentManager content, Vector2 position)
            : base(id)
        {
            this.spriteSheet = content.Load <Texture2D>(SPRITESHEET);

            this.spriteBounds = SPRITEBOUNDS;

            this.position = position;

            //Fire at the Player.
            PlayerShip Player         = ScrollingShooterGame.Game.Player;
            Vector2    positionVector = Player.GetPosition() - position;

            positionVector.Normalize();

            this.velocity = positionVector * VELOCITY;
        }