public Element(PlayerTypes PlayerType, ControllerTypes ControllerType, ControllerScheme scheme) { this.PlayerType = PlayerType; this.ControllerType = ControllerType; Logic(scheme); }
public void AddPlayer(string name, ControllerScheme scheme) { Player player = new Player(); player.Name = name; player.ControllerScheme = scheme; if (playerSelections.Find(x => x.IsControllerSchemeSame(player.ControllerScheme)) == null) { int index = playerSelections.FindIndex(x => x.IsSlotEmpty()); if (index == -1) { index = playerSelections.FindIndex(x => x.IsSlotAI()); if (index != -1) { RemovePlayer(playerSelections[index].Player); } } if (index != -1) { AddPlayer(player, index); } } }
void Awake() { // Tilting of player body to be that of camera angle mainBase.transform.rotation = cameraAngle.transform.rotation; // Locking of player's body rotation lastRotation = transform.rotation; // Creation and association of arms arm1Last = arm1; arm2Last = arm2; leftArm = Instantiate(armsList[arm1]); leftArm.transform.parent = transform; leftArm.transform.position = transform.position; rightArm = Instantiate(armsList[arm2]); rightArm.transform.parent = transform; rightArm.transform.position = transform.position; // Initial inventory UI setup inventoryBarSlotSelector1.transform.position = inventoryBarSlots.transform.GetChild(weaponSlot1).position; inventoryBarSlotSelector2.transform.position = inventoryBarSlots.transform.GetChild(weaponSlot2).position; refreshWeaponSprites(); // Getting rigidbody of Player rb = GetComponent <Rigidbody2D>(); m_Animator = gameObject.GetComponent <Animator>(); // Control scheme input system controls = new ControllerScheme(); controls.Gameplay.LeftTrigger.performed += ctx => { leftBoosterForce = true; }; controls.Gameplay.LeftTrigger.canceled += ctx => leftBoosterForce = false; controls.Gameplay.RightTrigger.performed += ctx => { rightBoosterForce = true; }; controls.Gameplay.RightTrigger.canceled += ctx => rightBoosterForce = false; controls.Gameplay.LeftArmMovement.performed += ctx => { leftMove = ctx.ReadValue <Vector2>(); leftRotationActive = true; }; controls.Gameplay.LeftArmMovement.canceled += ctx => leftRotationActive = false; controls.Gameplay.RightArmMovement.performed += ctx => { rightMove = ctx.ReadValue <Vector2>(); rightRotationActive = true; }; controls.Gameplay.RightArmMovement.canceled += ctx => rightRotationActive = false; controls.Gameplay.LeftPrime.performed += ctx => arm1ExplosiveArmed = !arm1ExplosiveArmed; controls.Gameplay.RightPrime.performed += ctx => arm2ExplosiveArmed = !arm2ExplosiveArmed; controls.Gameplay.WeaponSwapLeft.performed += ctx => isLeftSelected = true; controls.Gameplay.WeaponSwapLeft.canceled += ctx => isLeftSelected = false; controls.Gameplay.WeaponSwapRight.performed += ctx => isRightSelected = true; controls.Gameplay.WeaponSwapRight.canceled += ctx => isRightSelected = false; ShopManager.notifyitemselected += updateShopItemSelection; }
public bool IsControllerSchemeSame(ControllerScheme scheme) { if (this.scheme == null) { return(false); } return(this.scheme.Submit == scheme.Submit); }
private int GetFreePlayerSlot(ControllerScheme controllerScheme, int next) { if (playerSelections.Find(x => x.IsControllerSchemeSame(controllerScheme)) == null) { var players = playerSelections.FindAll(x => x.IsSlotEmpty()); return(playerSelections.IndexOf(players[next])); } return(-1); }
/* a idéia é que essas funções funcionem exatamente como as equivalentes delas na classe * Input do Unity, mas que já tratem e abstraiam as diferenças entre controladores e teclados, e, de alguma maneira, * tratem a situação de quando este controle estiver desconectado * */ //retorna identicamente à Input.GetAxis, mas somente usando o controle especificado //também retorna false se o controle estiver desconectado public static float GetAxis(ControllerScheme controller, string axisName) { if (IsControllerConnected(controller)) { string str = axisName + GetIdString(controller); return(Input.GetAxis(str)); } else { return(0.0f); } }
public void Leave() { player = null; scheme = null; JoinInfo.gameObject.SetActive(true); CarName.gameObject.SetActive(false); PlayerName.gameObject.SetActive(false); PreviousCarButton.gameObject.SetActive(false); NextCarButton.gameObject.SetActive(false); image.color = new Color(0, 0, 0, 0.5f); }
public void Join(Player player) { this.player = player; this.scheme = player.ControllerScheme; PlayerName.text = player.Name; JoinInfo.gameObject.SetActive(false); CarName.gameObject.SetActive(true); PlayerName.gameObject.SetActive(true); PreviousCarButton.gameObject.SetActive(true); NextCarButton.gameObject.SetActive(true); image.color = player.PrimaryColor; UpdateCar(); }
private void Logic(ControllerScheme scheme) { switch (ControllerType) { case ControllerTypes.Keyboard: controller = new KeyboardController(scheme); break; case ControllerTypes.Xbox: controller = new XboxController(scheme); break; case ControllerTypes.GhostAI: controller = new GhostAIController(); break; case ControllerTypes.PacAI: controller = new PacplayerAIController(); break; } }
//for a given controller scheme, tells if it is connected or not public static bool IsControllerConnected(ControllerScheme controller) { if (controller.mode == ControllerMode.Keyboard) { //teclado está sempre conectado(será?) return(true); } else { //se o joystick com esse índice estiver conectado, //(podemos testar se está conectado checando o nome retornado na string[] Input.GetJoystickNames) if (controller.index < joystickNames.Length && joystickNames[controller.index].Length > 0) { return(true); } else { return(false); } } }
public static bool GetKeyDown(ControllerScheme controller, string axisName) { if (IsControllerConnected(controller)) { //um hardcode temporário: if (controller.mode == ControllerMode.Joystick) { if (axisName == "Action1") { switch (controller.index) { //quadrado ou R1 num PS4 case 0: return(Input.GetKeyDown(KeyCode.Joystick1Button0) || Input.GetKeyDown(KeyCode.Joystick1Button5)); case 1: return(Input.GetKeyDown(KeyCode.Joystick2Button0) || Input.GetKeyDown(KeyCode.Joystick2Button5)); case 2: return(Input.GetKeyDown(KeyCode.Joystick3Button0) || Input.GetKeyDown(KeyCode.Joystick3Button5)); case 3: return(Input.GetKeyDown(KeyCode.Joystick4Button0) || Input.GetKeyDown(KeyCode.Joystick4Button5)); default: return(false); } } else if (axisName == "Action2") { switch (controller.index) { //X ou L1 num PS4 case 0: return(Input.GetKeyDown(KeyCode.Joystick1Button1) || Input.GetKeyDown(KeyCode.Joystick1Button4)); case 1: return(Input.GetKeyDown(KeyCode.Joystick2Button1) || Input.GetKeyDown(KeyCode.Joystick2Button4)); case 2: return(Input.GetKeyDown(KeyCode.Joystick3Button1) || Input.GetKeyDown(KeyCode.Joystick3Button4)); case 3: return(Input.GetKeyDown(KeyCode.Joystick4Button1) || Input.GetKeyDown(KeyCode.Joystick4Button4)); default: return(false); } } else if (axisName == "Start") { switch (controller.index) { //Start em ambos os controles //O: A princípio, não deve dar problema, mas o controle do ps4 tambem reconhece R2 como start. No do xbox não deve ter problema case 0: return(Input.GetKeyDown(KeyCode.Joystick1Button7) || Input.GetKeyDown(KeyCode.Joystick1Button9)); case 1: return(Input.GetKeyDown(KeyCode.Joystick2Button7) || Input.GetKeyDown(KeyCode.Joystick2Button9)); case 2: return(Input.GetKeyDown(KeyCode.Joystick3Button7) || Input.GetKeyDown(KeyCode.Joystick3Button9)); case 3: return(Input.GetKeyDown(KeyCode.Joystick4Button7) || Input.GetKeyDown(KeyCode.Joystick4Button9)); default: return(false); } } else { Debug.LogWarning("Comando estranho passado para a gambiarra dos controles"); return(false); //não deveria nunca cair aqui } } else { string str = axisName + GetIdString(controller); return(Input.GetAxis(str) > 0); } } else { return(false); } }
public void setupPlay() { gameUI = new BoardUI(logic.B, BoardWidth, BoardHeight, 0, 0); //((Window.ClientBounds.Width / 2) + (.5 * BoardWidth)), ((Window.ClientBounds.Height / 2) + (.5 * BoardHeight))); plays.Clear(); //plays.Add(new Element { et = ElementTypes.Ghost, X = 1, Y = 1 }); ControllerScheme scheme = new ControllerScheme(ControllerTypes.Keyboard); scheme.Add(Keys.Up); scheme.Add(Keys.Down); scheme.Add(Keys.Left); scheme.Add(Keys.Right); scheme.Add(Keys.Enter); ControllerScheme scheme2 = new ControllerScheme(ControllerTypes.Keyboard); scheme2.Add(Keys.W); scheme2.Add(Keys.S); scheme2.Add(Keys.A); scheme2.Add(Keys.D); scheme2.Add(Keys.Enter); byte controllerNum = 0; byte keyboardNum = 0; for (int i = 0; i < playerSetup.players.Count(); i++) { //Keyboard controlled ghost if (playerSetup.players[i].controllerType == ControllerTypes.Keyboard && playerSetup.players[i].IsGhost) { keyboardNum++; Element e = new Element(); e.et = ElementTypes.Ghost; if (keyboardNum == 1) { e.Control = new KeyboardInput(scheme); } else if (keyboardNum == 2) { e.Control = new KeyboardInput(scheme2); } else if (keyboardNum > 2 && e.et == ElementTypes.PacPlayer) { e.Control = new PacAI(e); } else if (keyboardNum > 2 && e.et == ElementTypes.Ghost) { e.Control = new GhostAI(e); } plays.Add(e); } //Keyboard controlled pacman else if (playerSetup.players[i].controllerType == ControllerTypes.Keyboard && !(playerSetup.players[i].IsGhost)) { keyboardNum++; Element e = new Element(); e.et = ElementTypes.PacPlayer; if (keyboardNum == 1) { e.Control = new KeyboardInput(scheme); } else if (keyboardNum == 2) { e.Control = new KeyboardInput(scheme2); } else if (keyboardNum > 2 && e.et == ElementTypes.PacPlayer) { e.Control = new PacAI(e); } else if (keyboardNum > 2 && e.et == ElementTypes.Ghost) { e.Control = new GhostAI(e); } plays.Add(e); } //AI controlled ghost else if ((playerSetup.players[i].controllerType == ControllerTypes.PacAI || playerSetup.players[i].controllerType == ControllerTypes.GhostAI) && (playerSetup.players[i].IsGhost)) { Element e = new Element(); e.et = ElementTypes.Ghost; e.Control = new GhostAI(e); e.IsAlive = true; plays.Add(e); } //AI controlled pacman else if ((playerSetup.players[i].controllerType == ControllerTypes.PacAI || playerSetup.players[i].controllerType == ControllerTypes.GhostAI) && !(playerSetup.players[i].IsGhost)) { Element e = new Element(); e.et = ElementTypes.PacPlayer; e.Control = new PacAI(e); e.IsAlive = true; plays.Add(e); } //Controller controlled pacman else if (playerSetup.players[i].controllerType == ControllerTypes.Xbox && !(playerSetup.players[i].IsGhost)) { controllerNum++; Element e = new Element(); e.et = ElementTypes.PacPlayer; if (controllerNum == 1) { e.Control = new ControllerInput(PlayerIndex.One); } else if (controllerNum == 2) { e.Control = new ControllerInput(PlayerIndex.Two); } else if (controllerNum == 3) { e.Control = new ControllerInput(PlayerIndex.Three); } else if (controllerNum == 4) { e.Control = new ControllerInput(PlayerIndex.Four); } else if (controllerNum > 4 && e.et == ElementTypes.PacPlayer) { //e.Control = new PacAI(); } else if (controllerNum > 4 && e.et == ElementTypes.Ghost) { e.Control = new GhostAI(e); } plays.Add(e); } //Controller controlled ghost else if (playerSetup.players[i].controllerType == ControllerTypes.Xbox && (playerSetup.players[i].IsGhost)) { controllerNum++; Element e = new Element(); e.et = ElementTypes.Ghost; if (controllerNum == 1) { e.Control = new ControllerInput(PlayerIndex.One); } else if (controllerNum == 2) { e.Control = new ControllerInput(PlayerIndex.Two); } else if (controllerNum == 3) { e.Control = new ControllerInput(PlayerIndex.Three); } else if (controllerNum == 4) { e.Control = new ControllerInput(PlayerIndex.Four); } else if (controllerNum > 4 && e.et == ElementTypes.PacPlayer) { //e.Control = new PacAI(); } else if (controllerNum > 4 && e.et == ElementTypes.Ghost) { e.Control = new GhostAI(e); } plays.Add(e); } } if (setup.gameMode == Setup.GameModes.Classic) { logic = new GameLogicClassic(); } else if (setup.gameMode == Setup.GameModes.GhostHunt) { logic = new GameLogicGhostHunt(); } boardToShare = logic.GameLogicSetup(plays); new Node(boardToShare, gameUI); Node.Handle.GenerateMatrix(); List <Sprite> sprites = new List <Sprite>(); foreach (Element Element in boardToShare.Elements) { Sprite gameSprite = Sprite.getSprite(Element, logic.B, (int)Math.Min(BoardWidth / logic.B.Width, BoardHeight / logic.B.Height)); gameUI.RegisterSprite(gameSprite); //Assigning the elements within sprites names. if (gameSprite.Element.et == ElementTypes.Ghost) { if (gameSprite.getColor() == Color.HotPink) { gameSprite.Element.Name = "Pinky"; } else if (gameSprite.getColor() == Color.Cyan) { gameSprite.Element.Name = "Inky"; } else if (gameSprite.getColor() == Color.Red) { gameSprite.Element.Name = "Blinky"; } else if (gameSprite.getColor() == Color.Orange) { gameSprite.Element.Name = "Clyde"; } } else if (gameSprite.Element.et == ElementTypes.PacPlayer) { gameSprite.Element.Name = "PacPlayer " + PacPlayerID; PacPlayerID += 1; } if (gameSprite.Element.et == ElementTypes.Ghost || gameSprite.Element.et == ElementTypes.PacPlayer) { sprites.Add(gameSprite); } } scoreManager = new ScoreManager(sprites); gameUI.LoadContent(Content); var aliveSprites = from m in plays.ToArray() where m.IsAlive where m.et == ElementTypes.PacPlayer || m.et == ElementTypes.Ghost select m; scoreBoards = new SBoardManager(this, aliveSprites.ToArray()); }
/* * This method is responsible for creating players. The types of players * as well as the controller and controller scheme are a must when calling * this method. * */ private void CreatePlayer(PlayerTypes humanOrAI, PlayerTypes pacOrGhost, ControllerTypes controller, ControllerScheme scheme) { Element player; if (pacOrGhost == PlayerTypes.PacPlayer) { player = new PacPlayer(); } else { player = new Ghost(); } if (humanOrAI == PlayerTypes.Human) { if (controller == ControllerTypes.Keyboard) { player.AddController(new KeyboardController(scheme)); } else { player.AddController(new XboxController(scheme)); } } else { if (pacOrGhost == PlayerTypes.PacPlayer) { player.AddController(new PacplayerAIController()); } else { player.AddController(new GhostAIController()); } } players.Add(player); }
private void Start() { carController = GetComponent <CarController>(); controllerScheme = carController.Car.Player.ControllerScheme; }
/* * This method is responsible for creating players. The types of players * as well as the controller and controller scheme are a must when calling * this method. * */ private void CreatePlayer(PlayerTypes humanOrAI, PlayerTypes pacOrGhost, ControllerTypes controller, ControllerScheme scheme) { Element player = new Element(); if (pacOrGhost == PlayerTypes.PacPlayer) { player.et = ElementTypes.PacPlayer; } else { player.et = ElementTypes.Ghost; } if (humanOrAI == PlayerTypes.Human) { if (controller == ControllerTypes.Keyboard) { player.AddController(new KeyboardInput(scheme)); } else { player.AddController(new ControllerInput(scheme)); } } else { player.AddController(new GhostAI(player)); } players.Add(player); }
private void MenuMode(ControllerScheme scheme, bool isPlayer1) { if (scheme.useStick) { // Stick releases if (Input.GetAxis(scheme.vertical) == 0) { axisUp = false; axisDown = false; } if (Input.GetAxis(scheme.horizontal) == 0) { axisLeft = false; axisRight = false; } // Stick presses if (!axisUp && Input.GetAxis(scheme.vertical) == -1) { CallEvent(InputType.UP, isPlayer1); axisUp = true; } if (!axisLeft && Input.GetAxis(scheme.horizontal) == -1) { CallEvent(InputType.LEFT, isPlayer1); axisLeft = true; } if (!axisRight && Input.GetAxis(scheme.horizontal) == 1) { CallEvent(InputType.RIGHT, isPlayer1); axisRight = true; } if (!axisDown && Input.GetAxis(scheme.vertical) == 1) { CallEvent(InputType.DOWN, isPlayer1); axisDown = true; } } else { // Arrow presses if (Input.GetKeyDown(scheme.up)) { CallEvent(InputType.UP, isPlayer1); axisUp = true; } if (Input.GetKeyDown(scheme.left)) { CallEvent(InputType.LEFT, isPlayer1); axisLeft = true; } if (Input.GetKeyDown(scheme.right)) { CallEvent(InputType.RIGHT, isPlayer1); axisRight = true; } if (Input.GetKeyDown(scheme.down)) { CallEvent(InputType.DOWN, isPlayer1); axisDown = true; } } // Button presses if (Input.GetKeyDown(scheme.select1)) { CallEvent(InputType.SEL1, isPlayer1); } if (Input.GetKeyDown(scheme.select2)) { CallEvent(InputType.SEL2, isPlayer1); } if (Input.GetKeyDown(scheme.select3)) { CallEvent(InputType.SEL3, isPlayer1); } if (Input.GetKeyDown(scheme.select4)) { CallEvent(InputType.SEL4, isPlayer1); } if (Input.GetKeyDown(scheme.action)) { CallEvent(InputType.ACTION, isPlayer1); } if (Input.GetKeyDown(scheme.mode)) { CallEvent(InputType.SWITCH, isPlayer1); } if (Input.GetKeyDown(scheme.start)) { CallEvent(InputType.START, isPlayer1); } SetButtonHold(InputType.HOLD_ACT, isPlayer1, Input.GetKey(scheme.action)); }
private static string GetIdString(ControllerScheme controller) { //constrói a string identificadora para um determinado controle. Isso só vai sentido se for seguido este mesmo padrão o input settings return(controller.mode.ToString() + controller.index.ToString()); }