Example #1
1
        public override void Create()
        {
            base.Create();

            cControl = new XboxController(SlimDX.XInput.UserIndex.One);
            pControl = new XboxController(SlimDX.XInput.UserIndex.Two);

            GameObject cursor = new Cursor(cControl);
            GameObject player = new Player(pControl);
            GameObject cannon1 = new Cannon();
            cannon1.Position.X = 365;
            cannon1.Position.Y = -265;
            GameObject cannon2 = new Cannon();
            cannon2.Position.X = 365;
            cannon2.Position.Y = 265;
            GameObject cannon3 = new Cannon();
            cannon3.Position.X = -365;
            cannon3.Position.Y = 265;
            GameObject cannon4 = new Cannon();
            cannon4.Position.X = -365;
            cannon4.Position.Y = -265;
            ObjectManager.AddGameObject(cursor);
            ObjectManager.AddGameObject(player);
            ObjectManager.AddGameObject(cannon1);
            ObjectManager.AddGameObject(cannon2);
            ObjectManager.AddGameObject(cannon3);
            ObjectManager.AddGameObject(cannon4);
        }
Example #2
0
    // Use this for initialization
    private InputManager()
    {
        //Hard-setting Keybinds for players 1 and 2 here for now. Eventually implement options.
        PlayerKeybindArray [0].UpKey = KeyCode.W;
        PlayerKeybindArray [0].DownKey = KeyCode.S;
        PlayerKeybindArray [0].LeftKey = KeyCode.A;
        PlayerKeybindArray [0].RightKey = KeyCode.D;
        PlayerKeybindArray [0].LTurnKey = KeyCode.Q;
        PlayerKeybindArray [0].RTurnKey = KeyCode.E;
        PlayerKeybindArray [0].GraborThrowKey = KeyCode.F;
        PlayerKeybindArray[0].AbilityKey = KeyCode.R;

        PlayerKeybindArray [1].UpKey = KeyCode.I;
        PlayerKeybindArray [1].DownKey = KeyCode.K;
        PlayerKeybindArray [1].LeftKey = KeyCode.J;
        PlayerKeybindArray [1].RightKey = KeyCode.L;
        PlayerKeybindArray [1].LTurnKey = KeyCode.U;
        PlayerKeybindArray [1].RTurnKey = KeyCode.O;
        PlayerKeybindArray [1].GraborThrowKey = KeyCode.Semicolon;
        PlayerKeybindArray[1].AbilityKey = KeyCode.P;

        PlayerKeybindArray [0].SelectKey = KeyCode.Return; //Only exists once to prevent game from "double-pausing"
        PlayerKeybindArray [0].ExitKey = KeyCode.Escape;

        for (int i = 0; i < ControllerArray.Length; i++)
        {
            ControllerArray[i] = new XboxController(i);
        }
    }
    private static void Initialize()
    {
        for (int i = 0; i < NUMBER_OF_CONTROLLERS; ++i)
        {
            m_XboxControllers[i] = new XboxController();
            m_XboxControllers[i].ControllerIndex = (PlayerIndex)i;

            m_IsInitialized = true;
        }

        UpdateState();
    }
Example #4
0
	public static Player Create(XboxController i)
	{

		Player player = (GameObject.Instantiate(Game.Instance.Settings.PlayerPrefabs[(int)i - 1].gameObject) as GameObject).GetComponent<Player>();
		player.rigidbody.isKinematic = true;
		MeshRenderer [] renderers = player.GetComponentsInChildren<MeshRenderer>();
		foreach (MeshRenderer r in renderers) {
			if (r.tag != "PasDeCouleur")
				r.material.color = Game.Instance.Settings.PlayerColors [(int)i - 1];
		}
		player.controller = i;
		return player;
	}
Example #5
0
        public override void Update()
        {
            base.Update();

            pControl = pControl == null ? new XboxController(SlimDX.XInput.UserIndex.Two) : pControl;

            if (!GameOver && (ObjectManager.GetAllObjectsByName("CANNON").Count == 0 ||
                ObjectManager.GetObjectByName("PLAYER") == null))
            {
                TextManager.AddText("RESTART", "Press START to restart", FontTypes.Arial32);
                TextObject text = TextManager.GetTextObjectByName("RESTART");
                text.Position.X = -Game.WindowWidth / 2;
                text.Position.Y = Game.WindowHeight / 2;
                GameOver = true;
            }

            if (GameOver)
            {
                pControl.Update();
                if (cControl.IsTriggered(XboxKeys.START) || pControl.IsTriggered(XboxKeys.START))
                    GameStateManager.GoToState(new Level());
            }
        }
		/// <summary> 
		/// 	Returns the float number of the specified axis from a specified controller without Unity's smoothing filter. 
		/// </summary>
		/// <param name='axis'> 
		/// 	An identifier for the specified Xbox axis to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the axis.
		/// </param>
		public static float GetAxisRaw(XboxAxis axis, XboxController controller)
		{
			if (controller == XboxController.All)
				return GetAxisRaw(axis);

			int controllerNumber = (int)controller;

			float r = 0.0f;
			
			if(OnWindowsNative())
			{
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
					
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);
				
				if(axis == XboxAxis.LeftTrigger || axis == XboxAxis.RightTrigger)
				{
					r = XInputGetAxisState(ctrlrState.Triggers, axis);
				}
				else
				{
					r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
				}
			}
			
			else
			{
				string axisCode = DetermineAxisCode(axis, controllerNumber);
				
				r = Input.GetAxisRaw(axisCode);
				r = AdjustAxisValues(r, axis, controllerNumber);
			}
				
			return r;
		}
		// From @ProjectEnder
		/// <summary> 
		/// 	Returns <c>true</c> at the frame the specified button is Pressed by a specified controller. 
		/// 	Does NOT work on Linux with Wired Controllers.
		/// </summary>
		/// <param name='button'> 
		/// 	Identifier for the Xbox button to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the button.
		/// </param>
		public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
		{
			if (controller == XboxController.All)
				return GetDPadDown(padDirection);

			int controllerNumber = (int)controller;

			bool r = false;
			
			if(OnWindowsNative())
			{
				if(Time.frameCount < 2)
				{
					return false;
				}
				
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);
				GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber);
				
				if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed ) &&
				   ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Released ) )
				{
					return true;
				}
			}
			
			else
			{
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, controllerNumber);
					r = Input.GetKeyDown(inputCode);
				}
				else if(OnLinux() && IsControllerWireless(controllerNumber))
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
					r = Input.GetKeyDown(inputCode);
				}
				else
				{
					//Place Holder for Wired Linux
					r = false;
				}
			}
			
			return r;
		}
		/// <summary> 
		/// 	Returns <c>true</c> if the specified D-Pad direction is pressed down by a specified controller. 
		/// </summary>
		/// <param name='padDirection'> 
		/// 	An identifier for the specified D-Pad direction to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the D-Pad.
		/// </param>
		public static bool GetDPad(XboxDPad padDirection, XboxController controller)
		{
			if (controller == XboxController.All)
				return GetDPad(padDirection);

			int controllerNumber = (int)controller;

			bool r = false;
			
			if(OnWindowsNative())
			{
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);

				if( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed )
				{
					return true;
				}
			}
			
			else
			{
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, controllerNumber);
					r = Input.GetKey(inputCode);
				}
				else if(OnLinux() && IsControllerWireless(controllerNumber))
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
					r = Input.GetKey(inputCode);
				}
				else // Windows Web Player and Linux Wired Controller
				{
					inputCode = DetermineDPad(padDirection, controllerNumber);
					
					switch(padDirection)
					{
						case XboxDPad.Up: 		r = Input.GetAxis(inputCode) > 0; break;
						case XboxDPad.Down: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Left: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Right:	r = Input.GetAxis(inputCode) > 0; break;
						
						default: r = false; break;
					}
				}
			}
			
			return r;
		}
		/// <summary> 
		/// 	Returns <c>true</c> at the frame the specified button is released by a specified controller. 
		/// </summary>
		/// <param name='button'> 
		/// 	Identifier for the Xbox button to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the button.
		/// </param>
		public static bool GetButtonUp(XboxButton button, XboxController controller)
		{
			if (button.IsDPad())
				return GetDPadUp(button.ToDPad(), controller);

			if (controller == XboxController.All)
				return GetButtonUp(button);

			int controllerNumber = (int)controller;

			if(OnWindowsNative())
			{
				if(Time.frameCount < 2)
				{
					return false;
				}
				
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);
				GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber);
				
				if( ( XInputGetButtonState(ctrlrState.Buttons, button) == ButtonState.Released ) &&
				    ( XInputGetButtonState(ctrlrStatePrev.Buttons, button) == ButtonState.Pressed ) )
				{
					return true;
				}
			}
			
			else
			{
				string btnCode = DetermineButtonCode(button, controllerNumber);
				
				if(Input.GetKeyUp(btnCode))
				{
					return true;
				}
			}
			
			return false;
		}
 public void Start()
 {
     _selectedController = XboxController.RetrieveController( 0 );
     XboxController.StartPolling();
 }
        private static float XInputApplyDeadzone(float rawAxisValue, XboxAxis axis, XboxController controller)
        {
            float finalValue = rawAxisValue;
            float deadzone = 0.0f;

            // Find the deadzone
            switch(axis)
            {
            case XboxAxis.LeftStickX:
                deadzone = XciHandler.Instance.Deadzones.LeftStickX[(int) controller];
                break;
            case XboxAxis.LeftStickY:
                deadzone = XciHandler.Instance.Deadzones.LeftStickY[(int) controller];
                break;
            case XboxAxis.RightStickX:
                deadzone = XciHandler.Instance.Deadzones.RightStickX[(int) controller];
                break;
            case XboxAxis.RightStickY:
                deadzone = XciHandler.Instance.Deadzones.RightStickY[(int) controller];
                break;
            case XboxAxis.LeftTrigger:
                deadzone = XciHandler.Instance.Deadzones.LeftTrigger[(int) controller];
                break;
            case XboxAxis.RightTrigger:
                deadzone = XciHandler.Instance.Deadzones.RightTrigger[(int) controller];
                break;
            }

            // Clear axis value if less than the deadzone
            if(Mathf.Abs(rawAxisValue) < deadzone)
            {
                finalValue = 0.0f;
            }
            // Remap the axis value from interval [0,1] to [deadzone,1]
            else
            {
                finalValue = (Mathf.Abs(rawAxisValue) * (1 - deadzone)) + deadzone;
                finalValue = finalValue * Mathf.Sign(rawAxisValue);
            }

            return finalValue;
        }
Example #12
0
 public XboxInput(XboxController controller)
 {
     this.controller = controller;
 }