Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //poll the acceleration value
            Vector3 acceleration = Accelerometer.GetState().Acceleration;

            logoVelocity.X += acceleration.X;
            logoVelocity.Y += -acceleration.Y;

            logoPosition += logoVelocity;

            // keep the sprite on the screen - clamp X
            Viewport viewport = graphics.GraphicsDevice.Viewport;

            if (logoPosition.X < 0)
            {
                logoPosition.X = 0;
                logoVelocity.X = 0;
            }
            else if (logoPosition.X > viewport.Width - asteroidTexture.Width)
            {
                logoPosition.X = viewport.Width - asteroidTexture.Width;
                logoVelocity.X = 0;
            }

            // keep the sprite on the screen - clamp Y
            if (logoPosition.Y < 0)
            {
                logoPosition.Y = 0;
                logoVelocity.Y = 0;
            }
            else if (logoPosition.Y > viewport.Height - asteroidTexture.Height)
            {
                logoPosition.Y = viewport.Height - asteroidTexture.Height;
                logoVelocity.Y = 0;
            }

            base.Update(gameTime);
        }