Ejemplo n.º 1
0
        /// <summary>
        /// The collision box is created based on a rectangle passed by parameter.
        /// This rectangle gives the dimension of the desired rectangle that will
        /// be converted to 4 points (Corners), every corner is a vertex of the
        /// rectangle, the CurrentRotatedCorner saves the current position of the
        /// rectangle around its owner.
        /// </summary>
        /// <param name="Owner">Owner of the box where it is going to be wrapped around.</param>
        /// <param name="Rectangle">Source Rectangle used as reference.</param>
        /// <param name="CollisionOffset">Offset of the rectangle around the owner.</param>
        public CollisionBox(Mobile Owner, Rectangle Rectangle, Vector2 CollisionOffset)
        {
            owner           = Owner;
            collisionOffset = CollisionOffset;

            corner    = new Vector2[4];
            corner[0] = Rectangle.Location.ToVector2();
            corner[1] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, 0);
            corner[2] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, Rectangle.Height);
            corner[3] = Rectangle.Location.ToVector2() + new Vector2(0, Rectangle.Height);

            rotatedBoxCenter = boxCenter = (corner[0] + corner[1] + corner[2] + corner[3]) / 4f;

            rotatedCorner    = new Vector2[4];
            rotatedCorner[0] = Rectangle.Location.ToVector2();
            rotatedCorner[1] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, 0);
            rotatedCorner[2] = Rectangle.Location.ToVector2() + new Vector2(Rectangle.Width, Rectangle.Height);
            rotatedCorner[3] = Rectangle.Location.ToVector2() + new Vector2(0, Rectangle.Height);

#if DEBUG
            debugRectangle = new DebugRectangle(Color.Red);
            debugCrosshair = new DebugCrosshair(Color.Red);
            debugCircle    = new DebugCircle(Color.Black, 25);
            debugLine      = new DebugLine(Color.White);

            DebugHandler.Instance.Add(debugRectangle);
            DebugHandler.Instance.Add(debugCrosshair);
            DebugHandler.Instance.Add(debugCircle);
            DebugHandler.Instance.Add(debugLine);
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Crosshair must be initialized inside the Concrete Mobile class after its name is set.
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="isAlly"></param>
        public Crosshair(Mobile mobile)
        {
            //Save References
            this.mobile = mobile;

            //Initialize Crosshair/Pointer Sprites
            crosshairFrame = new Sprite($"Interface/InGame/HUD/Crosshair/CrosshairFrame",
                                        new Vector2(0, 0), DepthParameter.CrosshairFrame);

            crosshairRangeIndicatorList = new List <Sprite>()
            {
                new Sprite($"Interface/InGame/HUD/Crosshair/{mobile.MobileType}{ShotType.S1}" + (mobile.IsEnemy ? "Enemy":"Ally"),
                           new Vector2(0, 0), DepthParameter.CrosshairAimRangeIndicator),
                new Sprite($"Interface/InGame/HUD/Crosshair/{mobile.MobileType}{ShotType.S2}" + (mobile.IsEnemy ? "Enemy":"Ally"),
                           new Vector2(0, 0), DepthParameter.CrosshairAimRangeIndicator),
                new Sprite($"Interface/InGame/HUD/Crosshair/{mobile.MobileType}{ShotType.SS}" + (mobile.IsEnemy ? "Enemy":"Ally"),
                           new Vector2(0, 0), DepthParameter.CrosshairAimRangeIndicator),
            };
            selectedCrosshairRangeIndicator = crosshairRangeIndicatorList[0];

            CrosshairPointer = new Sprite("Interface/InGame/HUD/Crosshair/Pointer",
                                          new Vector2(0, 0), DepthParameter.CrosshairPointer);

            //Initialize Crosshair Components
            crosshairPreset          = crosshairPresets[mobile.MobileType][mobile.SelectedShotType].Clone();
            crosshairDesiredRotation = 0f;

            if (mobile.IsPlayable)
            {
                crosshairAngleList = new List <NumericSpriteFont>()
                {
                    new NumericSpriteFont(FontType.HUDBlueCrosshairTrueAngle, 3, Parameter.HUDCrosshairAngleIndicator, textAnchor: TextAnchor.Middle, attachToCamera: false),
                    new NumericSpriteFont(FontType.HUDBlueCrosshairFalseAngle, 3, Parameter.HUDCrosshairAngleIndicator, textAnchor: TextAnchor.Middle, attachToCamera: false)
                };

                selectedCrosshairAngle = crosshairAngleList[0];
            }

            //Initialize Shooting Angle
            aimPreset     = mobile.MobileMetadata.MobileAimPreset[ShotType.S1];
            ShootingAngle = (aimPreset.AimTrueRotationMin + aimPreset.AimTrueRotationMax) / 2;

            CrosshairPointer.Rotation = crosshairFrame.Rotation + MathHelper.ToRadians(270 + ShootingAngle);

#if DEBUG
            //DEBUG
            debugCrosshair1 = new DebugCrosshair(Color.HotPink);
            debugCrosshair2 = new DebugCrosshair(Color.DarkTurquoise);
            DebugHandler.Instance.Add(debugCrosshair1);
            DebugHandler.Instance.Add(debugCrosshair2);
#endif
            if (mobile.IsPlayable)
            {
                FadeElement();
            }
            else
            {
                HideElement();
            }
        }