Exemplo n.º 1
0
        /// <summary>
        /// Handles the CursorUpdate event.
        /// </summary>
        /// <param name="sender">Always null.</param>
        /// <param name="e">Data of event.</param>
        private void CursorUpdate_Handler(object sender, CursorUpdateArgs e)
        {
            // Check the cursor identifier
            if (this.CursorIdentifier == e.Identifier)
            {
                if (this.Enabled)
                {
                    if (this.Moving)
                    {
                        // If the foot of the unit is inside the area.
                        Vector2 footPosition = new Vector2(e.Position.X, e.Position.Y + this.Unit.Texture.Height / 8);
                        if (Vector2.Distance(footPosition, this.Area.Position) < this.Limit - 10)
                        {
                            // Updates the position of the unit.
                            this.Unit.Position = new Vector2(e.Position.X - this.Unit.Texture.Width / 2, e.Position.Y - this.Unit.Texture.Height / 8);
                        }
                    }
                    else if (this.Orienting)
                    {
                        // Touch was inside of the area to orient.
                        if (Vector2.Distance(e.Position, this.Area.Position) < this.Area.Radius)
                        {
                            // Calculates the angle between the unit and the touch.
                            Vector2 distance = new Vector2(e.Position.X - this.Area.Position.X, e.Position.Y - this.Area.Position.Y);
                            double  angle    = MathHelper.ToDegrees((float)Math.Atan2(distance.X, distance.Y));

                            // Unit looking to down.
                            if (angle >= -45 && angle <= 45)
                            {
                                this.Unit.Orientation = Orientation.Down;
                            }

                            // Unit looking to right.
                            else if (angle >= 45 && angle <= 135)
                            {
                                this.Unit.Orientation = Orientation.Right;
                            }

                            // Unit looking to left.
                            else if (angle >= -135 && angle <= -45)
                            {
                                this.Unit.Orientation = Orientation.Left;
                            }

                            // Unit looking to up.
                            else
                            {
                                this.Unit.Orientation = Orientation.Up;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handles the CursorUpdate event.
 /// </summary>
 /// <param name="sender">Always null.</param>
 /// <param name="e">Data of event.</param>
 private void CursorUpdate_Handler(object sender, CursorUpdateArgs e)
 {
     // If the aim is enabled and aiming.
     if (this.Enabled && this.Aiming)
     {
         // If the aim is inside the area
         Vector2 areaPosition = new Vector2(this.Unit.Position.X + this.Unit.Texture.Width / 2, this.Unit.Position.Y + this.Unit.Texture.Height / 4);
         if (Vector2.Distance(e.Position, areaPosition) < (this.Limit / 2) - (this.AimAlly.Width / 2))
         {
             // Updates the position of the aim.
             this.PositionField = e.Position;
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the CursorUpdate event.
        /// </summary>
        /// <param name="sender">Always null.</param>
        /// <param name="e">Data of event.</param>
        private void CursorUpdate_Handler(object sender, CursorUpdateArgs e)
        {
            // Check the cursor identifier
            if (this.CursorIdentifier == e.Identifier)
            {
                // If the aim is enabled and aiming.
                if (this.Enabled && this.Aiming)
                {
                    // If the aim is inside the area.
                    if (Vector2.Distance(e.Position, this.Area.Position) < this.Area.Radius - (this.AimAlly.Width / 2))
                    {
                        // Updates the position of the aim.
                        this.PositionField = e.Position;

                        // Calculates the angle between the aim and the unit.
                        Vector2 distance = new Vector2(this.Position.X - this.Area.Position.X, this.Position.Y - this.Area.Position.Y);
                        double  angle    = MathHelper.ToDegrees((float)Math.Atan2(distance.X, distance.Y));

                        // Unit looking to down.
                        if (angle >= -45 && angle <= 45)
                        {
                            this.Unit.Orientation = Orientation.Down;
                        }

                        // Unit looking to right.
                        else if (angle >= 45 && angle <= 135)
                        {
                            this.Unit.Orientation = Orientation.Right;
                        }

                        // Unit looking to left.
                        else if (angle >= -135 && angle <= -45)
                        {
                            this.Unit.Orientation = Orientation.Left;
                        }

                        // Unit looking to up.
                        else
                        {
                            this.Unit.Orientation = Orientation.Up;
                        }
                    }
                }
            }
        }