/* * 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); }
/// <summary> /// Set the keys with ControllerScheme /// </summary> public KeyboardInput(ControllerScheme scheme) { state = Keyboard.GetState(); Up = scheme[0]; Down = scheme[1]; Left = scheme[2]; Right = scheme[3]; Start = scheme[4]; }
/* * 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); }
public ControllerInput(ControllerScheme scheme) { state = GamePad.GetState(scheme.playerIndex); }
public XboxController(ControllerScheme scheme) { this.scheme = scheme; }
public KeyboardController(ControllerScheme scheme) { this.scheme = scheme; }
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()); }