예제 #1
0
 /// <summary>
 /// Handles the XBOX movement for the player
 /// </summary>
 private void HandleXboxMovement(InputHelper inputHelper)
 {
     if (inputHelper.ControllerConnected(controllerNumber)) //Check if the controller is connected
     {
         if (inputHelper.ButtonPressed(controllerNumber, Buttons.A))
         {
             weapon.IsAttacking = true;
             this.weapon.Attack(GameWorld.Find("monsterLIST") as GameObjectList, GameWorld.Find("TileField") as GameObjectGrid);
             if (weapon.PreviousAttackHit)
             {
                 PlaySFX("attack_hit");
             }
             else
             {
                 PlaySFX("attack_miss");
             }
         }
         if (inputHelper.ButtonPressed(controllerNumber, Buttons.B))
         {
             if (!weapon.AbilityMain.IsOnCooldown)
             {
                 weapon.IsAttacking = true;
                 this.weapon.UseMainAbility(GameWorld.Find("monsterLIST") as GameObjectList, GameWorld.Find("TileField") as GameObjectGrid);
                 PlaySFX("basic_ability");
             }
             else
             {
                 PlaySFX("ability_not_ready");
             }
         }
         //Interact button
         if (inputHelper.IsButtonDown(controllerNumber, Buttons.Y))
         {
             InteractCollisionChecker();
         }
         if (inputHelper.ButtonPressed(controllerNumber, Buttons.X))
         {
             SwitchtoAIChecker();
             return;
         }
         //Movement
         walkingdirection   = inputHelper.WalkingDirection(controllerNumber) * this.movementSpeed;
         walkingdirection.Y = -walkingdirection.Y;
     }
 }
예제 #2
0
    /// <summary>
    /// Method for handling input for the character
    /// </summary>
    public override void HandleInput(InputHelper inputHelper)
    {
        if (playerControlled)
        {
            Vector2 previousPosition = this.position;
            if (this.xboxControlled && !inputHelper.ControllerConnected(controllerNumber))
            {
                FullBrickEpicDungeon.DungeonCrawler.mouseVisible = true;
                // will replace with another gamestate that tells you to reconnect your controller
                GameEnvironment.GameStateManager.SwitchTo("pauseState");
            }

            // Handle normal movement
            if (!IsDowned && !IsOnIceChecker())
            {
                velocity = Vector2.Zero;
                if (xboxControlled)
                {
                    HandleXboxMovement(inputHelper);
                }
                else
                {
                    HandleKeyboardMovement(inputHelper);
                }

                this.position += walkingdirection;

                // Play walking SFX
                if (walkingdirection != Vector2.Zero && stepSoundTimer.IsExpired)
                {
                    PlaySFX("walk");
                    stepSoundTimer.Reset();
                }
                if (walkingdirection != Vector2.Zero)
                {
                    previousWalkingDirection = walkingdirection;
                }
                // Play Animations
                PlayAnimationDirection(walkingdirection);
                weapon.SwordDirectionCheckerManager(previousWalkingDirection);
                walkingdirection = Vector2.Zero;
                base.HandleInput(inputHelper);
            }
            // Handle ice movement
            else if (!IsDowned)
            {
                if (xboxControlled)
                {
                    HandleXboxIceMovement(inputHelper);
                }
                else
                {
                    HandleKeyboardIceMovement(inputHelper);
                }

                if (iceSpeed != Vector2.Zero && stepSoundTimer.IsExpired)
                {
                    PlaySFX("ice_slide");
                    stepSoundTimer.Reset();
                }
                base.HandleInput(inputHelper);
            }

            //Check if maiden collides with solid object, else adjust the character position
            if (!SolidCollisionChecker())
            {
                this.iceSpeed = new Vector2(0, 0);

                //Check if collision is comes from y value
                this.position.X = previousPosition.X;
                //if there still is collision, recreate old position and check for x value
                if (!SolidCollisionChecker())
                {
                    this.position.X += previousWalkingDirection.X;
                    this.position.Y  = previousPosition.Y;
                    if (!SolidCollisionChecker())
                    {
                        this.position = previousPosition;
                        PlayAnimation("idle");
                    }
                }
                blockinput = false;
            }
        }
    }