private void ControllerInput(PlayerIndex i, Buttons b, GamePadMessage m) { if (m == GamePadMessage.Pressed && b == Buttons.Start) { if (_players[i] == null) { Vector2 spawnPos = GetSpawnPosition(); GameObject go = new GameObject(string.Format("player_{0}", i)); Console.WriteLine("Spawning Player: " + go.Name); go.Transform.Position = spawnPos; go.Transform.Scale = new Vector2(0.25f); var p = go.AddComponent<Player>(); Model2D model = new Model2D(go, string.Format("Player\\hero{0}", (int)i + 1)); go.AddComponent(model); model.UseAnimations = true; var rigid = go.AddComponent<RigidBody>(); rigid.HasDrag = true; p.Index = i; _players[i] = p; if (i == PlayerIndex.One) Camera.Instance.TrackingObject = go; } } }
private void ControllerSub(PlayerIndex i, GamePadMessage m) { switch (m) { case GamePadMessage.Connected: if(!_players.ContainsKey(i)) { // make the value null because the player has not yet joined _players.Add(i, null); } break; case GamePadMessage.Disconnected: default: // default will be disconnected if (_players.ContainsKey(i)) { Player p = _players[i]; // Destroy the object but keep the score if (p != null) { Scene.DestroyObject(p.GameObject); _players[i] = null; } } break; } }
private void InputHandler(PlayerIndex index, Buttons b, GamePadMessage message) { // simple check if(Index != index) return; switch (b) { case Buttons.A: if (message == GamePadMessage.Released) return; Jump(); break; case Buttons.RightShoulder: Camera.Instance.CameraScale += new Vector2(0.01f); break; case Buttons.LeftShoulder: Camera.Instance.CameraScale -= new Vector2(0.01f); break; case Buttons.X: if (message == GamePadMessage.Released) return; SpawnPlatform(); break; case Buttons.RightTrigger: if(message == GamePadMessage.Pressed) { SpawnBullet(); } break; } }
private void SendGamePadMessage(PlayerIndex index, GamePadMessage message) { int length = _controllerSubscriptions.Count; for (int i = 0; i < length; i++) { if(_controllerSubscriptions[i] != null) _controllerSubscriptions[i](index, message); } }
private void SendButtonGamePadMessage(PlayerIndex index, Buttons b, GamePadMessage message) { int length = _controllerButtonEvents.Count; for (int i = 0; i < length; i++) { if(_controllerButtonEvents[i] != null) _controllerButtonEvents[i](index, b, message); } }
private void OnControllerInput(PlayerIndex index, Buttons button, GamePadMessage message) { if(button == Buttons.Back && message == GamePadMessage.Pressed) { _gizmos = !_gizmos; } if(button == Buttons.DPadRight && message == GamePadMessage.Pressed) { RunUpdate(_localTime); } }