Example #1
0
        public static void RENDER_CONTROLLER(SpriteBatch sb, ControllerState State, Rectangle area, Color pColor)
        {
            Camera.draw(sb, BASE, area);
            Camera.draw(sb, P_COLOR, area, pColor);
            foreach (KeyValuePair <ControllerButton, Image> pair in ImageList)
            {
                if (State.IsButtonDown(pair.Key))
                {
                    Camera.draw(sb, pair.Value, area);
                }
            }
            Color leftTrigger = pColor;

            leftTrigger.A = (byte)(255 * State.LeftTrigger);
            Color rightTrigger = pColor;

            rightTrigger.A = (byte)(255 * State.RightTrigger);
            Camera.draw(sb, LEFT_TRIG, area, leftTrigger);
            Camera.draw(sb, RIGHT_TRIG, area, rightTrigger);

            Rectangle leftStickLoc = area;

            leftStickLoc.X += (int)(factor(area) * State.LeftStick.X * STICK_MAX * .5f);
            leftStickLoc.Y -= (int)(factor(area) * State.LeftStick.Y * STICK_MAX * .5f);
            if (State.LeftStick != Vector2.Zero)
            {
                Camera.draw(sb, LEFT_STICK, leftStickLoc, Color.Red);
            }
            Rectangle rightStickLoc = area;

            rightStickLoc.X += (int)(factor(area) * State.RightStick.X * STICK_MAX * .5f);
            rightStickLoc.Y -= (int)(factor(area) * State.RightStick.Y * STICK_MAX * .5f);
            if (State.RightStick != Vector2.Zero)
            {
                Camera.draw(sb, RIGHT_STICK, rightStickLoc, Color.Red);
            }
        }
Example #2
0
 public bool IsNewButton(Buttons button)
 {
     return(PreviousControllerState.IsButtonUp(button) && ControllerState.IsButtonDown(button));
 }
Example #3
0
        public virtual void Update(TimeSpan dt, List <Direction> limiters, ControllerState controller)
        {
            Limiters = limiters;
            C        = controller;

            bool canMoveDown  = !limiters.Contains(Direction.Down);
            bool canMoveUp    = !limiters.Contains(Direction.Up);
            bool canMoveLeft  = !limiters.Contains(Direction.Right);
            bool canMoveRight = !limiters.Contains(Direction.Left);

            bool cs1 = false;
            bool cs2 = false;
            bool cs3 = false;
            bool cs4 = false;

            if (Confused)
            {
                cs1 = Extensions.RandomBool();
                cs2 = Extensions.RandomBool();
                cs3 = Extensions.RandomBool();
                cs4 = Extensions.RandomBool();
            }

            _currentMovement = Movement.Idle;

            HealthBar.Value = Health;

            #region Vibrating Health
            if (_vibratingHealth)
            {
                if (Extensions.GetMS() - _lastVibrateTime > Health + 200)
                {
                    _lastVibrateTime    = Extensions.GetMS();
                    _lastVibrateStarted = Extensions.GetMS();
                    controller.StartVibrate(0.7f, 0.7f);
                }
                if (Extensions.GetMS() - _lastVibrateStarted > 100)
                {
                    controller.StopVibrate();
                }
            }
            #endregion

            #region Satus Updates
            if (Stunned && Extensions.GetMS() - _lastStunTime > _stunDuration)
            {
                Stunned = false;
            }
            if (Confused && Extensions.GetMS() - _lastConfuseTime > _confuseDuration)
            {
                Confused = false;
            }
            if (Extensions.GetMS() - _lastManaGain > _manaGainDelay)
            {
                if (Mana < 5)
                {
                    Mana += 1;
                }
            }
            #endregion

            #region Physics
            if (canMoveDown && !Flying && !Dead)
            {
                Position.Y += (int)_gravityAcceleration;
                if (Program.Game.InsideWall(this) != null)
                {
                    Position.Y          -= (int)_gravityAcceleration;
                    _gravityAcceleration = Program.Game.Gravity * 5;
                    Jumping = false;
                }
                _gravityAcceleration += Program.Game.Gravity;
                _currentMovement      = _gravityAcceleration > JumpStrength ? Movement.Fall : Movement.Jump;
            }
            else
            {
                _gravityAcceleration = 0;
                Jumping = false;
            }
            #endregion

            #region Controller Input

            if (controller.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.LeftShoulder))
            {
                Health -= 10;
                if (Health < 0)
                {
                    Health = 0;
                }
            }
            else
            {
                if (Health > MaxHealth)
                {
                    Health = MaxHealth;
                }
            }

            if (!ActionLocked)
            {
                if ((controller.WasButtonPressed(Microsoft.Xna.Framework.Input.Buttons.A)) && !Stunned && !Dead)
                {
                    if (!Jumping)
                    {
                        Jumping = true;
                    }
                }
                if (Jumping && !Flying && !Dead)
                {
                    if (canMoveUp)
                    {
                        Position.Y -= JumpStrength;
                        if (Program.Game.InsideWall(this) != null)
                        {
                            Position.Y += JumpStrength;
                            Jumping     = false;
                        }
                    }
                    else
                    {
                        Jumping = false;
                    }
                }

                if (($"{C.LeftThumbstickDirection}".Contains("Right") || cs1) && canMoveRight && !Stunned && !Dead)
                {
                    Position.X     += Speed;
                    FacingDirection = Direction.Right;
                    if (!FlipLocked)
                    {
                        FlipHorizontally = false;
                    }
                    if (!canMoveDown)
                    {
                        _currentMovement = Movement.Walk;
                    }
                }
                if (($"{C.LeftThumbstickDirection}".Contains("Left") || cs2) && canMoveLeft && !Stunned && !Dead)
                {
                    Position.X     -= Speed;
                    FacingDirection = Direction.Left;
                    if (!FlipLocked)
                    {
                        FlipHorizontally = true;
                    }
                    if (!canMoveDown)
                    {
                        _currentMovement = Movement.Walk;
                    }
                }
                if (Flying)
                {
                    if ($"{C.LeftThumbstickDirection}".Contains("Up") && canMoveUp && !Stunned && !Dead)
                    {
                        Position.Y -= Speed;
                    }
                    if ($"{C.LeftThumbstickDirection}".Contains("Down") && canMoveDown && !Stunned && !Dead)
                    {
                        Position.Y += Speed;
                    }
                }

                if (controller.WasButtonPressed(Microsoft.Xna.Framework.Input.Buttons.B) && !Stunned && !Dead && Mana >= Ability1Cost)
                {
                    Mana -= Ability1Cost;
                    Ability1();
                }

                if (controller.WasButtonPressed(Microsoft.Xna.Framework.Input.Buttons.X) && !Stunned && !Dead && Mana >= Ability2Cost)
                {
                    Mana -= Ability2Cost;
                    Ability2();
                }

                if (controller.WasButtonPressed(Microsoft.Xna.Framework.Input.Buttons.Y) && !Stunned && !Dead && Mana >= Ability3Cost)
                {
                    Mana -= Ability3Cost;
                    Ability3();
                }

                if (controller.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.LeftShoulder) && controller.IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.RightShoulder) && UltimatePercent == 1.0 && !Stunned && !Dead)
                {
                    UltimatePercent = 1.0;
                    Ultimate();
                }

                if (controller.RightTriggerPower > 0 && !Stunned && !Dead)
                {
                    var tms = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                    if (tms - _lastShotTime > ShotInterval)
                    {
                        Shoot();
                        _lastShotTime = tms;
                    }
                }
            }

            #endregion

            #region Movement Animation

            if (MovementAnimated)
            {
                if (_lastMovement != _currentMovement)
                {
                    //switch to current movement animation
                    switch (_currentMovement)
                    {
                    case Movement.Idle:
                        HardSetAnimation(IdleAnimation);
                        break;

                    case Movement.Fall:
                        HardSetAnimation(FallAnimation);
                        break;

                    case Movement.Jump:
                        HardSetAnimation(JumpAnimation);
                        break;

                    case Movement.Walk:
                        HardSetAnimation(WalkAnimation);
                        break;
                    }
                }
            }

            #endregion

            _previousPosition = Position;
            _lastMovement     = _currentMovement;
        }