Exemplo n.º 1
0
        /// <summary>
        /// Updates the Entity.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="input">The input.</param>
        /// <param name="delta">The delta.</param>
        public void Update(GraphicsDevice graphics, Input input, long delta)
        {
            LastDeath += delta;
            double percent = delta / 1000.0;

            if (input.Left())
            {
                Angle -= RadPerSecond * percent;
            }
            if (input.Right())
            {
                Angle += RadPerSecond * percent;
            }
            if (input.Thrusters())
            {
                Velocity += new Vector2(
                    (float)(Math.Cos(Angle) * AccelerationPerSecond * percent),
                    (float)(Math.Sin(Angle) * AccelerationPerSecond * percent));
            }
            else
            {
                Velocity = new Vector2((float)(Velocity.X * .98), (float)(Velocity.Y * .98));
            }

            Position += Velocity;

            if (Position.X > graphics.Viewport.Width + Width)
            {
                Position = new Vector2(-Width + 1, Position.Y);
            }
            else if (Position.X < -Width)
            {
                Position = new Vector2(graphics.Viewport.Width + Width, Position.Y);
            }
            if (Position.Y > graphics.Viewport.Height + Height)
            {
                Position = new Vector2(Position.X, -Height + 1);
            }
            else if (Position.Y < -Height)
            {
                Position = new Vector2(Position.X, graphics.Viewport.Height + Height);
            }
        }