Exemple #1
0
 public Weapon(ProjectileType pT, Texture2D texture, Vector2 position, Rectangle boundingBox, Range range = Range.Infinite) : base(texture, position, boundingBox)
 {
     //switch (range)
     //{
     //	case Range.Short:
     //		this.range = 200;
     //		break;
     //	case Range.Medium:
     //		this.range = 400;
     //		break;
     //	case Range.Long:
     //		this.range = 600;
     //		break;
     //	default:
     //		this.range = Projectile.INFINITE;
     //		break;
     //}
     this.range = (float)range;
     projType   = pT;
     this.angle = 0;                   //The angle of the weapon in radians
     this.dir   = Weapon_Dir.DownWest; //The direction of the weapon for drawing
 }
Exemple #2
0
        /// <summary>
        /// Parses Input during updates
        /// </summary>
        public void UpdateInput(GameTime gameTime, Vector2 camw)
        {
            timeMult = (float)gameTime.ElapsedGameTime.TotalSeconds / ((float)1 / 60);

            //Basic keyboard movement
            if (controlManager.ControlPressed(Control_Types.Forward))
            {
                if (controlManager.Mode == Control_Mode.GamePad)
                {
                    this.Y -= (gpState.ThumbSticks.Left.Y * timeMult) * MoveSpeed;
                }
                else
                {
                    this.Y -= this.MoveSpeed * timeMult;
                }
            }
            else if (controlManager.ControlPressed(Control_Types.Backward))
            {
                if (controlManager.Mode == Control_Mode.GamePad)
                {
                    this.Y -= (gpState.ThumbSticks.Left.Y * timeMult) * MoveSpeed;
                }
                else
                {
                    this.Y += this.MoveSpeed * timeMult;
                }
            }

            if (controlManager.ControlPressed(Control_Types.Right))
            {
                if (controlManager.Mode == Control_Mode.GamePad)
                {
                    this.X += (gpState.ThumbSticks.Left.X * timeMult) * MoveSpeed;
                }
                else
                {
                    this.X += this.MoveSpeed * timeMult;
                }
            }
            else if (controlManager.ControlPressed(Control_Types.Left))
            {
                if (controlManager.Mode == Control_Mode.GamePad)
                {
                    this.X += (gpState.ThumbSticks.Left.X * timeMult) * MoveSpeed;
                }
                else
                {
                    this.X -= this.MoveSpeed * timeMult;
                }
            }

            //Player reloading
            if (controlManager.ControlPressed(Control_Types.Reload))
            {
                this.currWeapon.ReloadWeapon();
            }

            //Calculates the angle between the player and the mouse
            //See below
            //   180
            //-90   90
            //    0
            if (controlManager.Mode == Control_Mode.KBM)
            {
                Vector2 campos = Camera.Instance.GetViewportPosition(this.X + 25, this.Y);
                angle = MathHelper.ToDegrees((float)Math.Atan2(mouseState.X - campos.X, mouseState.Y - campos.Y));
            }
            else
            {
                if (gpState.ThumbSticks.Right != Vector2.Zero)
                {
                    angle = MathHelper.ToDegrees((float)Math.Atan2(gpState.ThumbSticks.Right.X, gpState.ThumbSticks.Right.Y * -1));
                }
            }

            if ((controlManager.Mode == Control_Mode.GamePad && gpState.ThumbSticks.Right != Vector2.Zero) || controlManager.Mode == Control_Mode.KBM)
            {
                //Use angle to find player direction
                if ((angle < -157.5) || (angle > 157.5))
                {
                    if (angle < -157.5)
                    {
                        currWeapon.Dir = Weapon_Dir.UpWest;
                        this.Dir       = Entity_Dir.UpWest;
                    }
                    else
                    {
                        currWeapon.Dir = Weapon_Dir.UpEast;
                        this.Dir       = Entity_Dir.UpEast;
                    }
                }
                else if ((angle < 157.5) && (angle > 112.5) && this.Dir != Entity_Dir.UpRight)
                {
                    this.Dir       = Entity_Dir.UpRight;
                    currWeapon.Dir = Weapon_Dir.UpRight;
                }
                else if ((angle < 112.5) && (angle > 67.5) && this.Dir != Entity_Dir.Right)
                {
                    this.Dir       = Entity_Dir.Right;
                    currWeapon.Dir = Weapon_Dir.Right;
                }
                else if ((angle < 67.5) && (angle > 22.5) && this.Dir != Entity_Dir.DownRight)
                {
                    this.Dir       = Entity_Dir.DownRight;
                    currWeapon.Dir = Weapon_Dir.DownRight;
                }
                else if ((angle < -22.5) && (angle > -67.5) && this.Dir != Entity_Dir.DownLeft)
                {
                    this.Dir       = Entity_Dir.DownLeft;
                    currWeapon.Dir = Weapon_Dir.DownLeft;
                }
                else if ((angle < -67.5) && (angle > -112.5) && this.Dir != Entity_Dir.Left)
                {
                    this.Dir       = Entity_Dir.Left;
                    currWeapon.Dir = Weapon_Dir.Left;
                }
                else if ((angle < -112.5) && (angle > -157.5) && this.Dir != Entity_Dir.UpLeft)
                {
                    this.Dir       = Entity_Dir.UpLeft;
                    currWeapon.Dir = Weapon_Dir.UpLeft;
                }
                else if ((angle < 22.5) && (angle > -22.5))
                {
                    if (angle < 0)
                    {
                        currWeapon.Dir = Weapon_Dir.DownWest;
                        this.Dir       = Entity_Dir.DownWest;
                    }
                    else
                    {
                        currWeapon.Dir = Weapon_Dir.DownEast;
                        this.Dir       = Entity_Dir.DownEast;
                    }
                }
            }

            //Player switching weapons
            if (controlManager.ControlPressedControlPrevReleased(Control_Types.NextWeapon))
            {
                InteruptReload();
                Weapon_Dir oldDir = currWeapon.Dir;
                if (weaponId == weapons.Length - 1)
                {
                    weaponId = 0;
                }
                else
                {
                    weaponId++;
                }
                currWeapon = weapons[weaponId];
                //if (currWeapon == weapons[0]) { this.currWeapon = weapons[1];
                //else if (currWeapon == weapons[1]) { this.currWeapon = weapons[0]; }
                currWeapon.Dir = oldDir;
                UpdateWeapon(gameTime, camw);
            }
            else if (controlManager.ControlPressedControlPrevReleased(Control_Types.PrevWeapon))
            {
                InteruptReload();
                Weapon_Dir oldDir = currWeapon.Dir;
                if (weaponId == 0)
                {
                    weaponId = weapons.Length - 1;
                }
                else
                {
                    weaponId--;
                }
                //if (currWeapon == weapons[1]) { this.currWeapon = weapons[0]; }
                //else if (currWeapon == weapons[0]) { this.currWeapon = weapons[1]; }
                currWeapon     = weapons[weaponId];
                currWeapon.Dir = oldDir;
                UpdateWeapon(gameTime, camw);
            }
        }