Пример #1
0
 /// <summary>
 /// Private constructor.
 /// </summary>
 private Controller()
 {
     ControllerUpdate();
     for (uint i = 0; i < 7; i++)
     {
         if (Joystick.IsConnected(i))
         {
             id          = Joystick.GetIdentification(i);
             joystickPos = i;
             break;
         }
     }
     if (Joystick.IsConnected(joystickPos))
     {
         Console.WriteLine(Joystick.GetButtonCount(joystickPos));
         Console.WriteLine(Joystick.HasAxis(joystickPos, Joystick.Axis.X));
         Console.WriteLine(Joystick.HasAxis(joystickPos, Joystick.Axis.Y));
         Console.WriteLine(Joystick.HasAxis(joystickPos, Joystick.Axis.U));
         Console.WriteLine(Joystick.HasAxis(joystickPos, Joystick.Axis.R));
     }
 }
Пример #2
0
 public static void SetSelectedController()
 {
     if (selectedController == 1000)
     {
         for (uint i = 0; i < Joystick.Count; i++)
         {
             if (Joystick.IsConnected(i))
             {
                 for (uint j = 0; j < Joystick.GetButtonCount(i); j++)
                 {
                     if (Joystick.IsButtonPressed(i, j) &&
                         Joystick.HasAxis(i, Joystick.Axis.X) &&
                         Joystick.HasAxis(i, Joystick.Axis.Y))
                     {
                         selectedController = i;
                         controllerId       = (int)Joystick.GetIdentification(i).ProductId;
                         Console.WriteLine(controllerId);
                     }
                 }
             }
         }
     }
 }
Пример #3
0
        public static void UpdateStates()
        {
            Joystick.Update();
            AvailableControllers.Clear();

            for (byte i = 0; i < Joystick.Count; i++)
            {
                if (!Joystick.IsConnected(i))
                {
                    continue;
                }

                var ident = Joystick.GetIdentification(i);

                AvailableControllers.Add(new ControllerInfo
                {
                    Id          = i,
                    Name        = ident.Name,
                    ProductId   = (short)ident.ProductId,
                    VendorId    = (short)ident.VendorId,
                    ButtonCount = (short)Joystick.GetButtonCount(i)
                });
            }
        }
Пример #4
0
        internal void Events2()
        {
            //Graphics
            if (_context.GetGame.GetPlayer.IsAttack)
            {
                _context.GetGame.GetPlayer.Attack();
            }

            if (_context.GetGame.GetPlayer.HurtPlayer)
            {
                foreach (Monster monster in _context.GetGame.GetMonsters)
                {
                    monster.GetAttack.HurtPlayerAnimation();
                }
            }

            // Manette
            Joystick.Update();
            if (Joystick.IsConnected(0)) //Controller connected
            {
                // Actions
                for (uint i = 0; i < Joystick.GetButtonCount(0); i++) //Test tous les btn
                {
                    if (Joystick.IsButtonPressed(0, i))
                    {
                        switch (i)
                        {
                        case 0:     //A - Jump
                            if (_context.GetGame.GetPlayer.RealPosition.Y < _context.GetGame.GetMapObject.GetLimitMax.Y && _context.GetGame.GetPlayer.IsOnTheGround)
                            {
                                _context.GetGame.GetPlayer.Jump();
                            }
                            break;

                        case 1:     //B - Attack
                            _context.GetGame.GetPlayer.IsAttack = true;
                            _context.GetGame.GetPlayer.Attack();
                            break;
                        }
                    }
                }
                // Moves
                if (Joystick.GetAxisPosition(0, Joystick.Axis.X) >= 80) // Droite
                {
                    _moveTheMapOf += _context.GetGame.GetPlayer.MoveRight((float)_window.Size.X);
                }
                else if (Joystick.GetAxisPosition(0, Joystick.Axis.X) <= -80) // Gauche
                {
                    _moveTheMapOf -= _context.GetGame.GetPlayer.MoveLeft((float)_window.Size.X);
                }
                else if (_context.GetGame.GetPlayer.IsOnTheGround && !_context.GetGame.GetPlayer.IsAttack)
                {
                    _context.GetGame.GetPlayer.GetPlayerSprite.DefaultAnimation();
                }
            }
            else
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    //_context.GetGame.GetPlayer.GetLife.CurrentPoint = 0; // TEMPORARYYYYYYYYYYYYYYYYYY
                }
                else if (Keyboard.IsKeyPressed(_RightAction))
                {
                    _moveTheMapOf += _context.GetGame.GetPlayer.MoveRight((float)_window.Size.X);
                }
                else if (Keyboard.IsKeyPressed(_LeftAction))
                {
                    _moveTheMapOf -= _context.GetGame.GetPlayer.MoveLeft((float)_window.Size.X);
                }

                if (Keyboard.IsKeyPressed(_JumpAction))
                {
                    if (_context.GetGame.GetPlayer.RealPosition.Y < _context.GetGame.GetMapObject.GetLimitMax.Y && _context.GetGame.GetPlayer.IsOnTheGround)
                    {
                        _context.GetGame.GetPlayer.Jump();
                    }
                }

                if (Keyboard.IsKeyPressed(_AttackAction)) // ATTACK
                {
                    _context.GetGame.GetPlayer.IsAttack = true;
                    _context.GetGame.GetPlayer.Attack();
                }

                if (!Keyboard.IsKeyPressed(_LeftAction) && !Keyboard.IsKeyPressed(_RightAction) && !Keyboard.IsKeyPressed(_JumpAction) && !_context.GetGame.GetPlayer.IsAttack && !_context.GetGame.GetPlayer.HurtPlayer)
                {
                    _context.GetGame.GetPlayer.GetPlayerSprite.DefaultAnimation();
                }
            }
            // ------------------------------PLAYER 2
            //Graphics
            if (_context2.GetGame2.GetPlayer2.IsAttack2)
            {
                _context2.GetGame2.GetPlayer2.Attack2();
            }

            if (_context2.GetGame2.GetPlayer2.HurtPlayer2)
            {
                foreach (Monster monster in _context2.GetGame2.GetMonsters2)
                {
                    monster.GetAttack2.HurtPlayerAnimation2();
                }
            }
            else
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    //_context.GetGame.GetPlayer.GetLife.CurrentPoint = 0; // TEMPORARYYYYYYYYYYYYYYYYYY
                }
                else if (Keyboard.IsKeyPressed(_RightAction2))
                {
                    _moveTheMapOf2 += _context2.GetGame2.GetPlayer2.MoveRight2((float)_window.Size.X);
                }
                else if (Keyboard.IsKeyPressed(_LeftAction2))
                {
                    _moveTheMapOf2 -= _context2.GetGame2.GetPlayer2.MoveLeft2((float)_window.Size.X);
                }

                if (Keyboard.IsKeyPressed(_JumpAction2))
                {
                    if (_context2.GetGame2.GetPlayer2.RealPosition2.Y2 < _context2.GetGame2.GetMapObject2.GetLimitMax2.Y2 && _context2.GetGame2.GetPlayer2.IsOnTheGround2)
                    {
                        _context2.GetGame2.GetPlayer2.Jump2();
                    }
                }

                if (Keyboard.IsKeyPressed(_AttackAction2)) // ATTACK
                {
                    _context2.GetGame2.GetPlayer2.IsAttack2 = true;
                    _context2.GetGame2.GetPlayer2.Attack2();
                }

                if (!Keyboard.IsKeyPressed(_LeftAction2) && !Keyboard.IsKeyPressed(_RightAction2) && !Keyboard.IsKeyPressed(_JumpAction2) && !_context2.GetGame2.GetPlayer2.IsAttack2 && !_context2.GetGame2.GetPlayer2.HurtPlayer2)
                {
                    _context2.GetGame2.GetPlayer2.GetPlayerSprite2.DefaultAnimation2();
                }
            }
        }