public Vector2 AmountFaceRightUp(PlayerIndex? controllingPlayer, out PlayerIndex playerIndex)
        {
            Vector2 amountFaceRightUp;
            bool w, a, s, d;
            w = a = s = d = false;
            if (controllingPlayer.HasValue && GamePad.GetState((PlayerIndex)controllingPlayer).IsConnected)
            {
                playerIndex = (PlayerIndex)controllingPlayer; //we have the player set if it's a controller.
                amountFaceRightUp = GamePad.GetState((PlayerIndex)controllingPlayer).ThumbSticks.Left;
            }
            else
            {
                w = IsKeyDown(Keys.W, controllingPlayer, out playerIndex);
                a = IsKeyDown(Keys.A, controllingPlayer, out playerIndex);
                s = IsKeyDown(Keys.S, controllingPlayer, out playerIndex);
                d = IsKeyDown(Keys.D, controllingPlayer, out playerIndex);

                float amountFaceRight = ((d) ? 1.0f : 0.0f) + (((a)) ? -1.0f : 0.0f);
                float amountFaceUp = ((w) ? 1.0f : 0.0f) + (((s)) ? -1.0f : 0.0f);

                amountFaceRightUp = new Vector2(amountFaceRight, amountFaceUp);
            }

            return amountFaceRightUp;
        }
Esempio n. 2
0
 public IOManager(Game game, PlayerIndex playerIndex, float intervalMAJ)
     : base(game)
 {
     IntervalMAJ = intervalMAJ;
      IndexJoueur = playerIndex;
      Controles = DefinitionGamePad.DistribuerCommandes(IndexJoueur);
 }
        public float AmountForwardThruster(PlayerIndex? controllingPlayer, out PlayerIndex playerIndex)
        {
            float thrustAmount = 0.0f;
            if (controllingPlayer.HasValue && GamePad.GetState((PlayerIndex) controllingPlayer).IsConnected)
            {
                playerIndex = (PlayerIndex) controllingPlayer; //we have the player set if it's a controller.
                float forwardinput = GamePad.GetState((PlayerIndex) controllingPlayer).Triggers.Right;
                float backwardinput = GamePad.GetState((PlayerIndex) controllingPlayer).Triggers.Left;
                if (forwardinput - backwardinput < -0.001 || forwardinput - backwardinput > 0.001)
                    thrustAmount = forwardinput - backwardinput;
            }
            else
            {
                if (IsKeyDown(Keys.LeftAlt, controllingPlayer, out playerIndex))
                {
                    thrustAmount++;
                    MoritoFighterGame.MoritoFighterGameInstance.DisplayedMessages["keyup"] = "keyup is being pressed ";
                }
                if (IsKeyDown(Keys.RightAlt, controllingPlayer, out playerIndex))
                    thrustAmount--;

            }

            return thrustAmount;
        }
Esempio n. 4
0
        /// <summary>
        /// Evaluates the action against a given inputState.
        /// </summary>
        /// <param name="state">The InputState to test for the action.</param>
        /// <param name="controllingPlayer">The player to test, or null to allow any player.</param>
        /// <param name="player">If controllingPlayer is null, this is the player that performed the action.</param>
        /// <returns>True if the action occured, false otherwise.</returns>
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic
            ButtonPress buttonTest;
            KeyPress keyTest;
            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            // Now we simply need to invoke the appropriate methods for each button and key in our collections
            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }
            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            // If we got here, the action is not matched.
            player = PlayerIndex.One;
            return false;
        }
Esempio n. 5
0
 public Ship(PlayerIndex playerIndex, Texture2D txShipTexture,Texture2D txBulletTexture,WeaponTypes WeaponType)
 {
     this.player = playerIndex;
     this._weaponType = WeaponType;
     this.ShipTexture = txShipTexture;
     this._txBulletTexture = txBulletTexture;
 }
Esempio n. 6
0
 /// <summary>
 /// Checks for a "menu cancel" input action.
 /// The controllingPlayer parameter specifies which player to read input for.
 /// If this is null, it will accept input from any player. When the action
 /// is detected, the output playerIndex reports which player pressed it.
 /// </summary>
 public bool IsMenuCancel(PlayerIndex? controllingPlayer,
                          out PlayerIndex playerIndex)
 {
     return IsNewKeyPress(Keys.Escape, controllingPlayer, out playerIndex) ||
            IsNewButtonPress(Buttons.B, controllingPlayer, out playerIndex) ||
            IsNewButtonPress(Buttons.Back, controllingPlayer, out playerIndex);
 }
        public HalfPadState(ControlSide side, PlayerIndex controllerIndex)
        {
            GamePadState gamePadState = GamePad.GetState(controllerIndex);
            if (side == ControlSide.left)
            {
                stick1 = new Stick(gamePadState.ThumbSticks.Left);
                stick2 = new Stick(gamePadState.DPad.Up,
                                   gamePadState.DPad.Down,
                                   gamePadState.DPad.Left,
                                   gamePadState.DPad.Right);

                Btn1 = gamePadState.Buttons.LeftShoulder;
                Btn2 = (gamePadState.Triggers.Left < Controller.deadZone) ? ButtonState.Released : ButtonState.Pressed; //TODO: test
                Btn2AsTrigger = gamePadState.Triggers.Left;
                Btn3 = gamePadState.Buttons.LeftStick;

                BtnStart = gamePadState.Buttons.Back;
            }
            else //if (side == ControlSide.right)
            {
                stick1 = new Stick(gamePadState.ThumbSticks.Right);
                stick2 = new Stick(gamePadState.Buttons.Y,
                                   gamePadState.Buttons.A,
                                   gamePadState.Buttons.X,
                                   gamePadState.Buttons.B);

                Btn1 = gamePadState.Buttons.RightShoulder;
                Btn2 = (gamePadState.Triggers.Right < Controller.deadZone) ? ButtonState.Released : ButtonState.Pressed; //TODO: test
                Btn2AsTrigger = gamePadState.Triggers.Right;
                Btn3 = gamePadState.Buttons.RightStick;

                BtnStart = gamePadState.Buttons.Start;
            }
        }
 public override void Start()
 {
     this.controllingPlayer = ((CharacterInformationComponent)Parent.GetComponent("CharacterInformationComponent")).PlayerIndex;
     this.movementComponent = (MoveComponent)Parent.GetComponent("MoveComponent");
     this.bepuPhysicsComponent = (BepuPhysicsComponent)Parent.GetComponent("BepuPhysicsComponent");
     this.health = (VitalityComponent)Parent.GetComponent("VitalityComponent");
 }
Esempio n. 9
0
		public static string ShowKeyboardInput(
		 PlayerIndex player,           
         string title,
         string description,
         string defaultText,
		 bool usePasswordMode)
		{
			string result = defaultText; 

			TextFieldAlertView myAlertView = new TextFieldAlertView(usePasswordMode, title, defaultText);


			myAlertView.Title = title;
			myAlertView.Message = description;

			myAlertView.Clicked += delegate(object sender, UIButtonEventArgs e)
					{
						if (e.ButtonIndex == 1)
						{
								result = ((UIAlertView) sender).Subviews.OfType<UITextField>().Single().Text;
						}
					};
			myAlertView.Transform = MonoTouch.CoreGraphics.CGAffineTransform.MakeTranslation (0f, 110f);
			myAlertView.Show();

			return result;
		}
Esempio n. 10
0
 public FlxGamepad(PlayerIndex IndexOfPlayer)
 {
     index = IndexOfPlayer;
     leftVibe = 0;
     rightVibe = 0;
     vibeDuration = 0;
 }
Esempio n. 11
0
        public TheWaterArcanian(Vector2 position, PlayerIndex thePlayerIndex)
            : base(position, thePlayerIndex)
        {
            // Initialize texture
            texArcanianRight = "Arcanian/waterTurtleRight";
            texArcanianLeft = "Arcanian/waterTurtleLeft";
            texDyingRight = "Arcanian/waterTurtleDead_right";
            texDyingLeft = "Arcanian/waterTurtleDead_left";
            texShield = "Arcanian/watershieldsprite";
            Texture = texArcanianRight;

            // Initialize name
            mName = "Water Arcanian";

            // Initialize shield
            mShieldArt.SetTextureSpriteSheet(texShield, 4, 1, 0);
            mShieldArt.UseSpriteSheet = true;

            // Initliaze water skills
            SingleStream waterStream = new SingleStream();
            DoubleWaterStream doubleWaterStream = new DoubleWaterStream();
            UltimateWaterStream ultimateWaterStream = new UltimateWaterStream();

            // Initialize skill set with water skills
            mSkillSet = new SkillSet(waterStream, doubleWaterStream, ultimateWaterStream, null);

            // Add skills to global list of skills
            //G.ListOfSkills.Add(waterStream);
            //G.ListOfSkills.Add(doubleWaterStream);
            //G.ListOfSkills.Add(ultimateWaterStream);

            // Initialize HP Regen
            mHPRegenTimer = 0;
        }
Esempio n. 12
0
 public bool IsMenuSelected(PlayerIndex? controllingPlayer, out PlayerIndex playerIndex)
 {
     return IsNewKeyPress(Keys.Space, controllingPlayer, out playerIndex) ||
            IsNewKeyPress(Keys.Enter, controllingPlayer, out playerIndex) ||
            IsNewButtonPress(Buttons.A, controllingPlayer, out playerIndex) ||
            IsNewButtonPress(Buttons.Start, controllingPlayer, out playerIndex);
 }
Esempio n. 13
0
        public static Vector2 GetKeyboardInputDirection(PlayerIndex playerIndex)
        {
            Vector2 direction = Vector2.Zero;
            KeyboardState keyboardState = Keyboard.GetState(playerIndex);
            if (playerIndex == PlayerIndex.One)
            {
                if (keyboardState.IsKeyDown(Keys.W))
                {
                    direction.Y += -1;
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                    direction.Y += 1;
                }

            }

            if (playerIndex == PlayerIndex.Two)
            {
                if (keyboardState.IsKeyDown(Keys.Up))
                    direction.Y += -1;
                if (keyboardState.IsKeyDown(Keys.Down))
                    direction.Y += 1;
            }
            return direction;
        }
Esempio n. 14
0
 public KeyboardHelper( Game game, PlayerIndex index )
     : base(game)
 {
     PressCount = new Dictionary<MeanOfKey, int>();
     Config = new Dictionary<Keys, MeanOfKey>();
     this.playerIndex = index;
 }
Esempio n. 15
0
 public GamepadState this[PlayerIndex index]
 {
   get
   {
     return this.gamepadStates[index];
   }
 }
Esempio n. 16
0
        public UserControls(PlayerIndex playerIndex, float forceMag, float torqueMag, float forceShiftMag, float torqueShiftMag)
        {
            this.ForceMag = forceMag;
            this.TorqueMag = torqueMag;
            this.ForceShiftMag = forceShiftMag;
            this.TorqueShiftMag = torqueShiftMag;
            this.playerIndex = playerIndex;

            //default mappings
            KeyMappings[Keys.W] = UserControlKeys.MoveFoward;
            KeyMappings[Keys.S] = UserControlKeys.MoveBackward;
            KeyMappings[Keys.A] = UserControlKeys.MoveLeft;
            KeyMappings[Keys.D] = UserControlKeys.MoveRight;
            KeyMappings[Keys.Q] = UserControlKeys.TurnLeft;
            KeyMappings[Keys.Left] = UserControlKeys.TurnLeft;
            KeyMappings[Keys.E] = UserControlKeys.TurnRight;
            KeyMappings[Keys.Right] = UserControlKeys.TurnRight;
            KeyMappings[Keys.X] = UserControlKeys.MoveUp;
            KeyMappings[Keys.Z] = UserControlKeys.MoveDown;

            KeyMappings[Keys.Down] = UserControlKeys.LookUp;
            KeyMappings[Keys.Up] = UserControlKeys.LookDown;

            KeyMappings[Keys.T] = UserControlKeys.RollRight;
            KeyMappings[Keys.G] = UserControlKeys.RollLeft;

            KeyMappings[Keys.LeftShift] = UserControlKeys.Shifter;
            KeyMappings[Keys.RightShift] = UserControlKeys.Shifter;

            KeyMappings[Keys.LeftAlt] = UserControlKeys.PrimaryFire;
            KeyMappings[Keys.RightAlt] = UserControlKeys.SecondaryFire;
        }
Esempio n. 17
0
        public static void Poll(PlayerIndex index = PlayerIndex.One)
        {
            WalkLeft =
            JumpLeft =
            WalkRight =
            JumpRight =
            Jump =
            Idle =
            Shoot = false;
            var keys = Keyboard.GetState().GetPressedKeys().ToList();
            var padState =  GamePad.GetState(index);
            Idle = keys.Count == 0;
            Talk = keys.Any(k => k == Keys.P) || padState.Buttons.LeftShoulder == ButtonState.Pressed;
            Shoot = keys.Any(k => k == Keys.F) || padState.Buttons.A == ButtonState.Pressed;
            Jump = keys.Any(k => k == Keys.Up || k == Keys.Space) || padState.Buttons.B == ButtonState.Pressed;
            Reload = keys.Any(k => k == Keys.R) || padState.Buttons.RightShoulder == ButtonState.Pressed;

            if (keys.Any(k => k == Keys.Left) || padState.Buttons.LeftShoulder == ButtonState.Pressed)
            {
                if (Jump)
                    JumpLeft = true;
                WalkLeft = true;
            }

            if (keys.Any(k => k == Keys.Right) || padState.Buttons.RightShoulder == ButtonState.Pressed)
            {
                if (Jump)
                    JumpRight = true;
                WalkRight = true;
            }
        }
Esempio n. 18
0
        public LocalPlayer(World world, Vector2 position, Category collisionCat, float scale, float limbStrength, float limbDefense, bool evilSkin, Color color, PlayerIndex player)
            : base(world, position, collisionCat, scale, limbStrength, limbDefense, evilSkin, color)
        {
            this.player = player;
            punchBtnPressed = punchKeyPressed = false;
            kickBtnPressed = kickKeyPressed = false;
            shootBtnPressed = shootKeyPressed = false;
            trapBtnPressed = trapKeyPressed = false;
            usesKeyboard = !GamePad.GetState(player).IsConnected;
            lastShootAngle = 0f;

            jumpBtn = Buttons.A;
            rightBtn = Buttons.LeftThumbstickRight;
            leftBtn = Buttons.LeftThumbstickLeft;
            crouchBtn = Buttons.LeftTrigger;
            punchBtn = Buttons.X;
            kickBtn = Buttons.B;
            shootBtn = Buttons.RightTrigger;
            trapBtn = Buttons.Y;

            upKey = Keys.W;
            rightKey = Keys.D;
            leftKey = Keys.A;
            downKey = Keys.S;
            trapKey = Keys.T;
        }
Esempio n. 19
0
 protected override void OnCancel(PlayerIndex playerIndex)
 {
     MessageBoxScreen confirmExitMessageBox =
                             new MessageBoxScreen(Mario.Resource.ConfirmExitSample);
     confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
     ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
 }
Esempio n. 20
0
        public Penguin(PlayerIndex playerIndex, Vector2 pos, string colorCode)
            : base(pos.X, pos.Y, 36, 32, SMALL_SIZE, SMALL_MASS)
        {
            if (colorCode == "")
                color = Color.Blue;
            else if (colorCode == "_r")
                color = Color.Red;
            else if (colorCode == "_p")
                color = Color.Black;
            else
                color = Color.Green;

            this.colorCode        = colorCode;
            this.controller       = playerIndex;
            this.startingPosition = pos;
            this.Calories         = START_CALORIES;
            this.CurrentSize      = Size.Small;

            this.DashCost         = DASH_SMALL_COST;
            this.SpearCost        = SPEAR_SMALL_COST;
            this.MeleeCost        = MELEE_SMALL_COST;

            this.meleeCooldown    = MELEE_COOLDOWN;
            this.fireCooldown     = FIRE_COOLDOWN;

            this.isHit = false;
            this.canMelee = true;
            meleeTime = 0.0f;
            resetBlink();

            spearPoint = Vector2.Zero;
            spearCircle = new Circle(this.Bounds.center.X + 60, this.Bounds.center.Y, 50);
            spearDeflectorAura = new Circle(0, 0, 75);
        }
Esempio n. 21
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            PlayerIndex[] ControllingPlayers = new PlayerIndex[] { PlayerIndex.One, PlayerIndex.Two, PlayerIndex.Three, PlayerIndex.Four };

            // Look up inputs for the active player profile.
            //int playerIndex = (int)ControllingPlayer.Value;

            for (int playerIndex = 1; playerIndex <= totalPlayers; playerIndex++)
            {
                KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
                GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

                // The game pauses either if the user presses the pause button, or if
                // they unplug the active gamepad. This requires us to keep track of
                // whether a gamepad was ever plugged in, because we don't want to pause
                // on PC if they are playing with a keyboard and have no gamepad at all!
                bool gamePadDisconnected = !gamePadState.IsConnected &&
                                           input.GamePadWasConnected[playerIndex];

                if (input.IsPauseGame(ControllingPlayers[playerIndex-1]) || gamePadDisconnected)
                {
                    ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayers[playerIndex - 1]);
                }
            }
        }
Esempio n. 22
0
        public BaseGameState(Game game, GameStateManager manager)
            : base(game, manager)
        {
            GameRef = (Game1)game;

            playerIndexInControl = PlayerIndex.One;
        }
Esempio n. 23
0
 public GetInput(PlayerIndex index)
 {
     playerIndex = index;
     directionBoolArray = new bool[4] { upPressed, leftPressed, downPressed, rightPressed };
     oldKeyState = Keyboard.GetState();
     oldPadState = GamePad.GetState(playerIndex);
 }
Esempio n. 24
0
        public PlayerKeyboard(IInputDevice inputDevice, PlayerIndex playerIndex)
        {
            if (inputDevice == null) throw new ArgumentNullException("inputDevice");

            InputDevice = inputDevice;
            PlayerIndex = playerIndex;
        }
Esempio n. 25
0
 internal PlayerInput(PlayerIndex playerIndex)
 {
     PlayerIndex = playerIndex;
     Index = (int)playerIndex;
     Keyboard = new Keyboard();
     Gamepad = new Gamepad(PlayerIndex);
 }
Esempio n. 26
0
        public InputManager(InputType type, PlayerIndex player)
        {
            this.inputType = type;
              this.playerIndex = player;

              // Populate Dictionary Entries
              inputToKeys = new Dictionary<Inputs, Keys>();
              inputToKeys.Add(Inputs.A, Keys.A);
              inputToKeys.Add(Inputs.B, Keys.S);
              inputToKeys.Add(Inputs.Back, Keys.Escape);
              inputToKeys.Add(Inputs.Up, Keys.Up);
              inputToKeys.Add(Inputs.Down, Keys.Down);
              inputToKeys.Add(Inputs.Left, Keys.Left);
              inputToKeys.Add(Inputs.Right, Keys.Right);
              inputToKeys.Add(Inputs.Start, Keys.Enter);
              inputToKeys.Add(Inputs.X, Keys.Z);
              inputToKeys.Add(Inputs.Y, Keys.X);

              inputToButtons = new Dictionary<Inputs, Buttons>();
              inputToButtons.Add(Inputs.A, Buttons.A);
              inputToButtons.Add(Inputs.B, Buttons.B);
              inputToButtons.Add(Inputs.Back, Buttons.Back);
              inputToButtons.Add(Inputs.Up, Buttons.DPadUp);
              inputToButtons.Add(Inputs.Down, Buttons.DPadDown);
              inputToButtons.Add(Inputs.Left, Buttons.DPadLeft);
              inputToButtons.Add(Inputs.Right, Buttons.DPadRight);
              inputToButtons.Add(Inputs.Start, Buttons.Start);
              inputToButtons.Add(Inputs.X, Buttons.X);
              inputToButtons.Add(Inputs.Y, Buttons.Y);

              inputToMouse = new Dictionary<Inputs, MouseButton>();
              inputToMouse.Add(Inputs.A, MouseButton.Left);
              inputToMouse.Add(Inputs.B, MouseButton.Right);
              inputToMouse.Add(Inputs.X, MouseButton.Middle);
        }
Esempio n. 27
0
 /// <summary>
 /// When the user cancels the main menu, ask if they want to exit the sample.
 /// </summary>
 protected override void OnCancel(PlayerIndex playerIndex)
 {
     const string message = "Are you sure you want to exit?";
     var confirmExitMessageBox = new MessageBoxScreen(message);
     confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
     ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
 }
Esempio n. 28
0
        public EndScreen(PlayerIndex playerIndex, Color color)
        {
            Sprite bg = new Sprite();
            bg.LoadTexture(@"Assets/HeartBG");
            bg.Scale /= Controller.CurrentDrawCamera.zoom;
            this.AddChild(bg);

            heart = new Sprite();
            heart.LoadTexture(@"Assets/Heart");
            heart.Scale /= (Controller.CurrentDrawCamera.zoom * 1.1f);
            heart.Position.X += 110;
            this.AddChild(heart);

            slime = new Sprite();
            slime.LoadTexture(@"Assets/HeartSlime");
            slime.Scale /= (Controller.CurrentDrawCamera.zoom * 1.1f);
            slime.Position.X += 110;
            slime.Color = color;
            this.AddChild(slime);

            Label lbl = new Label("Player " + (float)(playerIndex + 1) + " has won!", Controller.FontController.GetFont("bigFont"));
            lbl.Position.X = ((Controller.ScreenSize.X / Controller.CurrentDrawCamera.zoom) / 2) - (lbl.Width / 2);
            AddChild(lbl);

            Label lblAdvance = new Label("Press A to apply CPR", Controller.FontController.GetFont("bigFont"));
            lblAdvance.Position.X = ((Controller.ScreenSize.X / Controller.CurrentDrawCamera.zoom) / 2) - (lblAdvance.Width / 2);
            lblAdvance.Position.Y = 550;
            AddChild(lblAdvance);

            ECGsound = Controller.Content.Load<SoundEffect>("sounds/ecg");
        }
Esempio n. 29
0
 public int this[PlayerIndex playerIndex]
 {
     get
     {
         return GetMatchScore(playerIndex);
     }
 }
Esempio n. 30
0
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            ButtonPress buttonTest;
            KeyPress keyTest;

            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }

            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            player = PlayerIndex.One;
            return false;
        }
 void FixedUpdate()
 {
     playerIndex = PlayerIndex.Three;
 }
Esempio n. 32
0
 //
 // Summary:
 //     Gets the current state of a game pad controller. Reference page contains
 //     links to related code samples.
 //
 // Parameters:
 //   playerIndex:
 //     Player index for the controller you want to query.
 public static GamePadState GetState(PlayerIndex playerIndex)
 {
     return(GetState(playerIndex, GamePadDeadZone.IndependentAxes));
 }
Esempio n. 33
0
 /// <summary>
 /// Handler for when the user has chosen a menu entry.
 /// </summary>
 protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
 {
     menuEntries[entryIndex].OnSelectEntry(playerIndex);
 }
Esempio n. 34
0
    void Update()
    {
        bool second_controller = false;

        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)i;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex    = testPlayerIndex;
                    playerIndexSet = true;

                    if (second_controller)
                    {
                        break;
                    }

                    second_controller = true;
                }
            }
        }


        prevState = state;
        state     = GamePad.GetState(playerIndex);

        if (sceneManaging.do_actions)
        {
            if (actual_shoot_time >= shoot_time)
            {
                if (state.ThumbSticks.Left.Y > 0.1f || Input.GetKey(up_input))
                {
                    rigidbody2D.AddForce(Vector2.up * speed * Time.deltaTime);
                    // pos.y += speed * Time.deltaTime;
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.UP);
                    animator.SetInteger("State", 0);
                    lastState = AnimStates.UP;

                    if (animator.GetBool("Idle"))
                    {
                        animator.SetBool("Idle", false);
                    }
                }
                else if (state.ThumbSticks.Left.Y < -0.1f || Input.GetKey(down_input))
                {
                    rigidbody2D.AddForce(Vector2.down * speed * Time.deltaTime);
                    //pos.y -= speed * Time.deltaTime;
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.DOWN);
                    animator.SetInteger("State", 1);
                    lastState = AnimStates.DOWN;

                    if (animator.GetBool("Idle"))
                    {
                        animator.SetBool("Idle", false);
                    }
                }
                else if (state.ThumbSticks.Left.X > 0.1f || Input.GetKey(right_input))
                {
                    rigidbody2D.AddForce(Vector2.right * speed * Time.deltaTime);
                    //pos.x += speed * Time.deltaTime;
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.RIGHT);
                    animator.SetInteger("State", 2);
                    lastState = AnimStates.RIGHT;

                    if (animator.GetBool("Idle"))
                    {
                        animator.SetBool("Idle", false);
                    }
                    //sprite.flipX = false;
                }
                else if (state.ThumbSticks.Left.X < -0.1f || Input.GetKey(left_input))
                {
                    rigidbody2D.AddForce(Vector2.left * speed * Time.deltaTime);
                    //pos.x -= speed * Time.deltaTime;
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.LEFT);
                    animator.SetInteger("State", 3);
                    lastState = AnimStates.LEFT;

                    if (animator.GetBool("Idle"))
                    {
                        animator.SetBool("Idle", false);
                    }
                    //sprite.flipX = true;
                }
                else
                {
                    if (!animator.GetBool("Idle"))
                    {
                        animator.SetBool("Idle", true);
                    }
                    animator.SetInteger("State", -1);
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.WAIT);
                }
            }
            else
            {
                if (!animator.GetBool("Idle"))
                {
                    animator.SetBool("Idle", true);
                }
                animator.SetInteger("State", -1);
                shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.WAIT);
                actual_shoot_time += Time.deltaTime;
            }


            if (actual_cooldown >= cooldown_shoot)
            {
                if (state.Buttons.LeftShoulder == ButtonState.Pressed || Input.GetKey(shoot_input))
                {
                    actual_cooldown   = 0.0f;
                    actual_shoot_time = 0.0f;
                    shadow_child.GetComponent <ShadowBehaviour>().SetPlayerInput(ShadowBehaviour.PlayerInput.SHOOT);
                    NotReallyFire();
                }
            }
            else
            {
                actual_cooldown += Time.deltaTime;
            }
        }
    }
Esempio n. 35
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="playerIndex"></param>
 public void Disconnect(PlayerIndex playerIndex)
 {
     Task.Factory.StartNew(() => WaitForDisconnect(playerIndex));
 }
Esempio n. 36
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public GamePadState GamePadPlayerPreviousState(PlayerIndex player)
 {
     return(_previousState[player]);
 }
Esempio n. 37
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public GamePadState GamePadPlayerCurrentState(PlayerIndex player)
 {
     return(_currentState[player]);
 }
Esempio n. 38
0
 public Vector2 GetPosition(PlayerIndex pIdx = PlayerIndex.One) =>
 InputStates.Mouse.CurrentState.Position.ToVector2();
Esempio n. 39
0
        // This is where we actually read in the controller input!
        private static GamePadState ReadState(PlayerIndex index, GamePadDeadZone deadZone)
        {
            IntPtr device = INTERNAL_devices[(int)index];

            if (device == IntPtr.Zero)
            {
                return(GamePadState.InitializedState);
            }

            // Do not attempt to understand this number at all costs!
            const float DeadZoneSize = 0.27f;

            // SDL_GameController
            if (INTERNAL_isGameController[(int)index])
            {
                // The "master" button state is built from this.
                Buttons gc_buttonState = (Buttons)0;

                // Sticks
                GamePadThumbSticks gc_sticks = new GamePadThumbSticks(
                    new Vector2(
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX
                            ) / 32768.0f,
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY
                            ) / -32768.0f
                        ),
                    new Vector2(
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX
                            ) / 32768.0f,
                        (float)SDL.SDL_GameControllerGetAxis(
                            device,
                            SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY
                            ) / -32768.0f
                        )
                    );
                gc_sticks.ApplyDeadZone(deadZone, DeadZoneSize);
                gc_buttonState |= READ_StickToButtons(
                    gc_sticks.Left,
                    Buttons.LeftThumbstickLeft,
                    Buttons.LeftThumbstickRight,
                    Buttons.LeftThumbstickUp,
                    Buttons.LeftThumbstickDown,
                    DeadZoneSize
                    );
                gc_buttonState |= READ_StickToButtons(
                    gc_sticks.Right,
                    Buttons.RightThumbstickLeft,
                    Buttons.RightThumbstickRight,
                    Buttons.RightThumbstickUp,
                    Buttons.RightThumbstickDown,
                    DeadZoneSize
                    );

                // Triggers
                GamePadTriggers gc_triggers = new GamePadTriggers(
                    (float)SDL.SDL_GameControllerGetAxis(device, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT) / 32768.0f,
                    (float)SDL.SDL_GameControllerGetAxis(device, SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT) / 32768.0f
                    );
                gc_buttonState |= READ_TriggerToButton(
                    gc_triggers.Left,
                    Buttons.LeftTrigger,
                    DeadZoneSize
                    );
                gc_buttonState |= READ_TriggerToButton(
                    gc_triggers.Right,
                    Buttons.RightTrigger,
                    DeadZoneSize
                    );

                // Buttons
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A) != 0)
                {
                    gc_buttonState |= Buttons.A;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B) != 0)
                {
                    gc_buttonState |= Buttons.B;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X) != 0)
                {
                    gc_buttonState |= Buttons.X;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y) != 0)
                {
                    gc_buttonState |= Buttons.Y;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK) != 0)
                {
                    gc_buttonState |= Buttons.Back;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE) != 0)
                {
                    gc_buttonState |= Buttons.BigButton;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START) != 0)
                {
                    gc_buttonState |= Buttons.Start;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK) != 0)
                {
                    gc_buttonState |= Buttons.LeftStick;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK) != 0)
                {
                    gc_buttonState |= Buttons.RightStick;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER) != 0)
                {
                    gc_buttonState |= Buttons.LeftShoulder;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) != 0)
                {
                    gc_buttonState |= Buttons.RightShoulder;
                }

                // DPad
                GamePadDPad gc_dpad;
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP) != 0)
                {
                    gc_buttonState |= Buttons.DPadUp;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN) != 0)
                {
                    gc_buttonState |= Buttons.DPadDown;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT) != 0)
                {
                    gc_buttonState |= Buttons.DPadLeft;
                }
                if (SDL.SDL_GameControllerGetButton(device, SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT) != 0)
                {
                    gc_buttonState |= Buttons.DPadRight;
                }
                gc_dpad = new GamePadDPad(gc_buttonState);

                // Compile the master buttonstate
                GamePadButtons gc_buttons = new GamePadButtons(gc_buttonState);

                return(new GamePadState(
                           gc_sticks,
                           gc_triggers,
                           gc_buttons,
                           gc_dpad
                           ));
            }

            // SDL_Joystick

            // We will interpret the joystick values into this.
            Buttons buttonState = (Buttons)0;

            // Sticks
            GamePadThumbSticks sticks = new GamePadThumbSticks(
                new Vector2(
                    READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_LX, device),
                    -READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_LY, device)
                    ),
                new Vector2(
                    READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_RX, device),
                    -READTYPE_ReadFloat(INTERNAL_joystickConfig.AXIS_RY, device)
                    )
                );

            sticks.ApplyDeadZone(deadZone, DeadZoneSize);
            buttonState |= READ_StickToButtons(
                sticks.Left,
                Buttons.LeftThumbstickLeft,
                Buttons.LeftThumbstickRight,
                Buttons.LeftThumbstickUp,
                Buttons.LeftThumbstickDown,
                DeadZoneSize
                );
            buttonState |= READ_StickToButtons(
                sticks.Right,
                Buttons.RightThumbstickLeft,
                Buttons.RightThumbstickRight,
                Buttons.RightThumbstickUp,
                Buttons.RightThumbstickDown,
                DeadZoneSize
                );

            // Buttons
            buttonState = READ_ReadButtons(device, DeadZoneSize);

            // Triggers
            GamePadTriggers triggers = new GamePadTriggers(
                READTYPE_ReadFloat(INTERNAL_joystickConfig.TRIGGER_LT, device),
                READTYPE_ReadFloat(INTERNAL_joystickConfig.TRIGGER_RT, device)
                );

            buttonState |= READ_TriggerToButton(
                triggers.Left,
                Buttons.LeftTrigger,
                DeadZoneSize
                );
            buttonState |= READ_TriggerToButton(
                triggers.Right,
                Buttons.RightTrigger,
                DeadZoneSize
                );

            // Compile the GamePadButtons with our Buttons state
            GamePadButtons buttons = new GamePadButtons(buttonState);

            // DPad
            GamePadDPad dpad = new GamePadDPad(buttons.buttons);

            // Return the compiled GamePadState.
            return(new GamePadState(sticks, triggers, buttons, dpad));
        }
Esempio n. 40
0
        //
        // Summary:
        //     Retrieves the capabilities of an Xbox 360 Controller.
        //
        // Parameters:
        //   playerIndex:
        //     Index of the controller to query.
        public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex)
        {
            // SDL_GameController Capabilities

            if (INTERNAL_isGameController[(int)playerIndex])
            {
                // An SDL_GameController will _always_ be feature-complete.
                return(new GamePadCapabilities()
                {
                    IsConnected = INTERNAL_devices[(int)playerIndex] != IntPtr.Zero,
                    HasAButton = true,
                    HasBButton = true,
                    HasXButton = true,
                    HasYButton = true,
                    HasBackButton = true,
                    HasStartButton = true,
                    HasDPadDownButton = true,
                    HasDPadLeftButton = true,
                    HasDPadRightButton = true,
                    HasDPadUpButton = true,
                    HasLeftShoulderButton = true,
                    HasRightShoulderButton = true,
                    HasLeftStickButton = true,
                    HasRightStickButton = true,
                    HasLeftTrigger = true,
                    HasRightTrigger = true,
                    HasLeftXThumbStick = true,
                    HasLeftYThumbStick = true,
                    HasRightXThumbStick = true,
                    HasRightYThumbStick = true,
                    HasBigButton = true,
                    HasLeftVibrationMotor = INTERNAL_HapticSupported(playerIndex),
                    HasRightVibrationMotor = INTERNAL_HapticSupported(playerIndex),
                    HasVoiceSupport = false
                });
            }

            // SDL_Joystick Capabilities

            IntPtr d = INTERNAL_devices[(int)playerIndex];

            if (d == IntPtr.Zero)
            {
                return(new GamePadCapabilities());
            }

            return(new GamePadCapabilities()
            {
                IsConnected = true,

                HasAButton = INTERNAL_joystickConfig.BUTTON_A.INPUT_TYPE != InputType.None,
                HasBButton = INTERNAL_joystickConfig.BUTTON_B.INPUT_TYPE != InputType.None,
                HasXButton = INTERNAL_joystickConfig.BUTTON_X.INPUT_TYPE != InputType.None,
                HasYButton = INTERNAL_joystickConfig.BUTTON_Y.INPUT_TYPE != InputType.None,
                HasBackButton = INTERNAL_joystickConfig.BUTTON_BACK.INPUT_TYPE != InputType.None,
                HasStartButton = INTERNAL_joystickConfig.BUTTON_START.INPUT_TYPE != InputType.None,
                HasDPadDownButton = INTERNAL_joystickConfig.DPAD_DOWN.INPUT_TYPE != InputType.None,
                HasDPadLeftButton = INTERNAL_joystickConfig.DPAD_LEFT.INPUT_TYPE != InputType.None,
                HasDPadRightButton = INTERNAL_joystickConfig.DPAD_RIGHT.INPUT_TYPE != InputType.None,
                HasDPadUpButton = INTERNAL_joystickConfig.DPAD_UP.INPUT_TYPE != InputType.None,
                HasLeftShoulderButton = INTERNAL_joystickConfig.SHOULDER_LB.INPUT_TYPE != InputType.None,
                HasRightShoulderButton = INTERNAL_joystickConfig.SHOULDER_RB.INPUT_TYPE != InputType.None,
                HasLeftStickButton = INTERNAL_joystickConfig.BUTTON_LSTICK.INPUT_TYPE != InputType.None,
                HasRightStickButton = INTERNAL_joystickConfig.BUTTON_RSTICK.INPUT_TYPE != InputType.None,
                HasLeftTrigger = INTERNAL_joystickConfig.TRIGGER_LT.INPUT_TYPE != InputType.None,
                HasRightTrigger = INTERNAL_joystickConfig.TRIGGER_RT.INPUT_TYPE != InputType.None,
                HasLeftXThumbStick = INTERNAL_joystickConfig.AXIS_LX.INPUT_TYPE != InputType.None,
                HasLeftYThumbStick = INTERNAL_joystickConfig.AXIS_LY.INPUT_TYPE != InputType.None,
                HasRightXThumbStick = INTERNAL_joystickConfig.AXIS_RX.INPUT_TYPE != InputType.None,
                HasRightYThumbStick = INTERNAL_joystickConfig.AXIS_RY.INPUT_TYPE != InputType.None,

                HasLeftVibrationMotor = INTERNAL_HapticSupported(playerIndex),
                HasRightVibrationMotor = INTERNAL_HapticSupported(playerIndex),
                HasVoiceSupport = false,
                HasBigButton = false
            });
        }
Esempio n. 41
0
 /// <summary>
 /// Checks for a "menu cancel" input action from the specified player.
 /// </summary>
 public bool IsMenuCancel(PlayerIndex playerIndex)
 {
     return(IsNewKeyPress(Keys.Escape, playerIndex) ||
            IsNewButtonPress(Buttons.B, playerIndex) ||
            IsNewButtonPress(Buttons.Back, playerIndex));
 }
Esempio n. 42
0
 public InputManager(PlayerIndex playerNumber)
 {
     this.playerNumber  = playerNumber;
     bufferRepeatAmount = 6;
 }
Esempio n. 43
0
 /// <summary>
 /// Helper for checking if a key was newly pressed during this update,
 /// by the specified player.
 /// </summary>
 public bool IsNewKeyPress(Keys key, PlayerIndex playerIndex)
 {
     return(CurrentKeyboardStates[(int)playerIndex].IsKeyDown(key) &&
            LastKeyboardStates[(int)playerIndex].IsKeyUp(key));
 }
Esempio n. 44
0
 /// <summary>
 /// Helper for checking if a button was newly pressed during this update,
 /// by the specified player.
 /// </summary>
 public bool IsNewButtonPress(Buttons button, PlayerIndex playerIndex)
 {
     return(CurrentGamePadStates[(int)playerIndex].IsButtonDown(button) &&
            LastGamePadStates[(int)playerIndex].IsButtonUp(button));
 }
Esempio n. 45
0
 public PlayerButton(Buttons button, PlayerIndex playerIndex)
 {
     Button             = button;
     CurrentPlayerIndex = playerIndex;
 }
Esempio n. 46
0
    // Update is called once per frame
    void Update()
    {
        float horiz = KeyInputHold(KeyCode.D, KeyCode.A);
        float vert  = KeyInputHold(KeyCode.W, KeyCode.S);

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int i = 0; i < 4; ++i)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)i;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex    = testPlayerIndex;
                    playerIndexSet = true;
                }
            }
        }

        prevState = state;
        state     = GamePad.GetState(playerIndex);

        Vector2 leftStick  = ApplyStickDeadzone(state.ThumbSticks.Left);
        Vector2 rightStick = ApplyStickDeadzone(state.ThumbSticks.Right);

        if (isRunningAnalogue)
        {
            if (leftStickCheckTimer < leftStickCheckTime)
            {
                leftStickCheckTimer += Time.deltaTime;
            }
            else
            {
                if (!leftStickCheck)
                {
                    isRunningAnalogue = false;
                }

                leftStickCheck      = false;
                leftStickCheckTimer = 0;
            }
        }

        // If left stick movement is being picked up
        if (leftStick != Vector2.zero)
        {
            // Clicking the left stick toggles running
            if (OnXInputButtonDown(prevState.Buttons.LeftStick, state.Buttons.LeftStick))
            {
                isRunningAnalogue = !isRunningAnalogue;
            }

            bool runCancel = false;
            playerController.MoveAnalogue(leftStick.x, leftStick.y, isRunningAnalogue, ref runCancel);

            if (runCancel)
            {
                isRunningAnalogue   = false;
                leftStickCheck      = false;
                leftStickCheckTimer = 0;
            }
            leftStickCheck = true;
        }
        else
        {
            playerController.MoveKeyboard(horiz, vert, Input.GetKey(KeyCode.LeftShift), Input.GetKey(KeyCode.LeftControl));
        }

        if (rightStick != Vector2.zero)
        {
            playerCam.Move(rightStick.x, rightStick.y);
        }
        else
        {
            playerCam.Move(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
        }

        float horizCam = state.ThumbSticks.Right.X != 0 ? state.ThumbSticks.Right.X * rightStickSensitivity : Input.GetAxisRaw("Mouse X");
        float vertCam  = state.ThumbSticks.Right.Y != 0 ? state.ThumbSticks.Right.Y * rightStickSensitivity : Input.GetAxisRaw("Mouse Y");
        //playerCam.SetAxes(horizCam, vertCam);

        bool aimInput = state.Triggers.Left > 0.1f || Input.GetMouseButton(1);
        bool jump     = prevState.Buttons.A == ButtonState.Released && state.Buttons.A == ButtonState.Pressed || Input.GetKeyDown(KeyCode.Space);
#else
        playerController.Move(horiz, vert);

        float horizCam = Input.GetAxisRaw("Mouse X");
        float vertCam  = Input.GetAxisRaw("Mouse Y");
        bool  aimInput = Input.GetMouseButton(1);
        bool  jump     = Input.GetKeyDown(KeyCode.Space);
#endif
    }
Esempio n. 47
0
 //Constructor
 public BaseGameState(Game game, GameStateManager manager)
     : base(game, manager)
 {
     gameRef = (Game1)game;
     playerIndexInControl = PlayerIndex.One;
 }
Esempio n. 48
0
 public MenuInput(PlayerIndex MyIndex)
 {
     this.MyIndex = MyIndex;
 }
Esempio n. 49
0
 public bool IsGamePadUp(PlayerIndex playerNumber)
 {
     return(gamepadButtons.Any(x => Input.GamePad(playerNumber).IsButtonUp(x)));
 }
Esempio n. 50
0
 [HideInInspector] public bool IsHalfMarkedByPlayer(PlayerIndex playerIndex)
 {
     return(halfMarkingPlayer == playerIndex && halfMarkingPlayer != PlayerIndex.PlayerIndexOutOfBounds);
 }
Esempio n. 51
0
 public GamePadInputs(PlayerIndex index)
 {
     playerIndex = index;
 }
Esempio n. 52
0
 public bool WasGamePadReleased(PlayerIndex playerNumber)
 {
     return(gamepadButtons.Any(x => Input.GamePad(playerNumber).WasButtonReleased(x)));
 }
Esempio n. 53
0
 /// <summary>
 /// Handler for when the user has cancelled the menu.
 /// </summary>
 protected virtual void OnCancel(PlayerIndex playerIndex)
 {
     ExitScreen();
 }
    // Update is called once per frame
    void Update()
    {
        // Find a PlayerIndex, for a single player game
        // Will find the first controller that is connected ans use it
        if (!playerIndexSet || !prevState.IsConnected)
        {
            for (int k = 0; k < 4; k++)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)k;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    Debug.Log(string.Format("GamePad found {0}", testPlayerIndex));
                    playerIndex    = testPlayerIndex;
                    playerIndexSet = true;
                }
            }
        }

        prevState = state;
        state     = GamePad.GetState(playerIndex);



        if (playerIndex == PlayerIndex.Three)
        {
            for (int i = 0; i < CharOptions.Length; i++)
            {
                if (i == P3CharIndex)
                {
                    P3part.sprite = CharOptions [i];
                }

                for (int p = 0; p < AbilityOptions.Length; p++)
                {
                    if (p == P3AbilityIndex)
                    {
                        P3part2.sprite = AbilityOptions [p];
                    }
                }
            }

            if (Input.GetButtonDown("P1A") && P3OptionIndex == 0)
            {
                if (P3CharIndex == 0)
                {
                    CharAudio.PlayOneShot(Duck);
                }

                if (P3CharIndex == 1)
                {
                    CharAudio.PlayOneShot(Duck);
                }

                if (P3CharIndex == 2)
                {
                    CharAudio.PlayOneShot(Unicorn);
                }

                if (P3CharIndex == 3)
                {
                    CharAudio.PlayOneShot(Eagle);
                }
            }


            if (prevState.Buttons.RightShoulder == ButtonState.Released && state.Buttons.RightShoulder == ButtonState.Pressed && P3OptionIndex == 0)
            {
                Audio.PlayOneShot(Navigate);

                if (P3CharIndex < CharOptions.Length - 1)
                {
                    P3CharIndex++;
                }
                else
                {
                    P3CharIndex = 0;
                }
            }

            if (prevState.Buttons.LeftShoulder == ButtonState.Released && state.Buttons.LeftShoulder == ButtonState.Pressed && P3OptionIndex == 0)
            {
                Audio.PlayOneShot(Navigate);

                if (P3CharIndex >= 1)
                {
                    P3CharIndex--;
                }
                else
                {
                    P3CharIndex = CharOptions.Length - 1;
                }
            }

            if (prevState.Buttons.RightShoulder == ButtonState.Released && state.Buttons.RightShoulder == ButtonState.Pressed && P3OptionIndex == 1)
            {
                Audio.PlayOneShot(Navigate);

                if (P3AbilityIndex < CharOptions.Length - 1)
                {
                    P3AbilityIndex++;
                }
                else
                {
                    P3AbilityIndex = 0;
                }
            }

            if (prevState.Buttons.LeftShoulder == ButtonState.Released && state.Buttons.LeftShoulder == ButtonState.Pressed && P3OptionIndex == 1)
            {
                Audio.PlayOneShot(Navigate);

                if (P3AbilityIndex >= 1)
                {
                    P3AbilityIndex--;
                }
                else
                {
                    P3AbilityIndex = AbilityOptions.Length - 1;
                }
            }

            if (prevState.Buttons.A == ButtonState.Released && state.Buttons.A == ButtonState.Pressed && P3OptionIndex < TotalOptions)
            {
                P3OptionIndex++;
            }

            if (prevState.Buttons.A == ButtonState.Released && state.Buttons.A == ButtonState.Pressed && P3OptionIndex == 2)
            {
                Audio.PlayOneShot(Confirm);
            }


            if (prevState.Buttons.A == ButtonState.Released && state.Buttons.A == ButtonState.Pressed && P3OptionIndex < TotalOptions && P3CharIndex == 4)
            {
                P3CharIndex = Random.Range(0, 4);
            }


            if (prevState.Buttons.B == ButtonState.Released && state.Buttons.B == ButtonState.Pressed)
            {
                P3OptionIndex--;
            }

            if (prevState.Buttons.B == ButtonState.Released && state.Buttons.B == ButtonState.Pressed && P3OptionIndex <= TotalOptions)
            {
                P3Ok = false;
            }


            if (P3OptionIndex == 0)
            {
                PlayerSelectBox.SetActive(true);
                PlayerAbilityBox.SetActive(false);
            }

            if (P3OptionIndex == 1)
            {
                PlayerAbilityBox.SetActive(true);
                PlayerSelectBox.SetActive(false);
            }

            if (P3OptionIndex == TotalOptions)
            {
                P3Ok = true;
            }

            if (P3OptionIndex == 2)
            {
                P3OK.SetActive(true);
            }
            else
            {
                P3OK.SetActive(false);
            }
        }
    }
Esempio n. 55
0
 public Vector2 GetPosition(PlayerIndex playerIndex = PlayerIndex.One) =>
 // TODO: resolve if you can have more than one binding for this?
 _bindingsByPlayer[(int)playerIndex].FirstOrDefault()?.GetPosition() ?? Vector2.Zero;
Esempio n. 56
0
 public static bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor)
 {
     SystemSound.Vibrate.PlaySystemSound();
     return(true);
 }
Esempio n. 57
0
 /// <summary>
 /// Init the xinput gamepad of this player index.
 /// </summary>
 private GamePad(PlayerIndex _playerIndex)
 {
     playerIndex  = _playerIndex;
     currentState = Microsoft.Xna.Framework.Input.GamePad.GetState(playerIndex);
     DeadZone     = GamePadDeadZone.IndependentAxes;
 } // GamePad
 // Use this for initialization
 void Start()
 {
     playerIndex = PlayerIndex.Three;
 }
Esempio n. 59
0
 /// <inheritdoc/>
 public bool IsGamePadHandled(PlayerIndex controller)
 {
   int index = (int)controller;
   return _areGamePadsHandled[index];
 }
Esempio n. 60
0
 public static GamePadState GetState(PlayerIndex playerIndex)
 {
     return(new GamePadState());                    // Please fix
     // TODO return new GamePadState((Buttons)GamePad.Instance._buttons,GamePad.Instance._leftStick,GamePad.Instance._rightStick);
 }