Ejemplo n.º 1
0
        public void SetMouse(MainCharacter MC, ProjectileManager PM, GameTime GT)
        {
            currentmouse = Mouse.GetState();
            Pos.X        = (currentmouse.X);
            Pos.Y        = (currentmouse.Y);
            if ((currentmouse.RightButton.Equals(ButtonState.Pressed)) & !(previousmouse.RightButton.Equals(ButtonState.Pressed)))
            {
                MC.AimPressed(this);
            }
            Distance = Math.Sqrt(Math.Pow((Pos.X - MC.ScreenPosition.X), 2.0f) + Math.Pow((Pos.Y - MC.ScreenPosition.Y), 2.0f));
            Vector2 Pointing = new Vector2();

            if (MC.Aimed)
            {
                Pointing = Pos - MC.ScreenPosition - Vector2.Transform(AimOffset, Matrix.CreateRotationZ(MC.Angle));
            }
            else
            {
                Pointing = Pos - MC.ScreenPosition - Vector2.Transform(Offset, Matrix.CreateRotationZ(MC.Angle));
            }
            Angle = (float)Math.Atan2(Pointing.Y, Pointing.X);
            // Angle = - (float)Math.Atan2((double)(MC.ScreenPosition.Y - Pos.Y),(double)(Pos.X - MC.ScreenPosition.X)) - (float)Math.Asin(Math.Abs(AimOffset.Y) / Distance);
            // reset angles if they go out of bounds and turn MC

            if (MC.Aimed)
            {
                if (MC.Angle < -1 * MathHelper.Pi)
                {
                    MC.Angle += MathHelper.TwoPi;
                }
                if (MC.Angle > MathHelper.Pi)
                {
                    MC.Angle -= MathHelper.TwoPi;
                }
                if (Math.Abs((Angle - MC.Angle)) <= MC.AimTurnSpeed)
                {
                    MC.Angle = Angle;
                }
                else if (Angle > MathHelper.PiOver2 & MC.Angle < -1 * MathHelper.PiOver2)
                {
                    MC.Angle -= MC.AimTurnSpeed;
                }
                else if (Angle <-1 * MathHelper.PiOver2 & MC.Angle> MathHelper.PiOver2)
                {
                    MC.Angle += MC.AimTurnSpeed;
                }
                else if (Angle > MC.Angle)
                {
                    MC.Angle += MC.AimTurnSpeed;
                }
                else
                {
                    MC.Angle -= MC.AimTurnSpeed;
                }
            }
            else if (Distance > 14)
            {
                MC.Angle = Angle;
            }
            MC.Fire(PM, currentmouse, GT);

            // cursor colour

            if (currentmouse.LeftButton.Equals(ButtonState.Pressed))
            {
                Colour = Color.Red;
            }
            else
            {
                Colour = Color.White;
            }
            previousmouse = currentmouse;
        }