Example #1
0
        public ControllerKeyboard(Game1 game)
        {
            Id     = -1;
            Active = true;
            ICommandController quit           = new CommandQuit(game);
            ICommandController downPress      = new CommandDownPress();
            ICommandController upPress        = new CommandUpPress();
            ICommandController leftPress      = new CommandLeftPress();
            ICommandController rightPress     = new CommandRightPress();
            ICommandController actionPress    = new CommandActionPress();
            ICommandController jumpPress      = new CommandJumpPress();
            ICommandController toggleVaria    = new CommandToggleVaria();
            ICommandController toggleMissile  = new CommandToggleMissile();
            ICommandController menuSelect     = new CommandMenuSelect(game, this);
            ICommandController pauseGame      = new CommandPauseGame();
            ICommandController fullScreen     = new CommandFullScreen();
            ICommandController moveCursorUp   = new CommandMoveCursorUp();
            ICommandController moveCursorDown = new CommandMoveCursorDown();
            ICommandController cheatUpgrades  = new CommandGiveAllPowerUps();
            ICommandController menuLeft       = new CommandMenuLeft();
            ICommandController menuRight      = new CommandMenuRight();

            _oldState = Keyboard.GetState();

            _gameCommands.Add(Keys.Q, quit);
            _gameCommands.Add(Keys.S, downPress);
            _gameCommands.Add(Keys.Down, downPress);
            _gameCommands.Add(Keys.W, upPress);
            _gameCommands.Add(Keys.Up, upPress);
            _gameCommands.Add(Keys.A, leftPress);
            _gameCommands.Add(Keys.Left, leftPress);
            _gameCommands.Add(Keys.D, rightPress);
            _gameCommands.Add(Keys.Right, rightPress);
            _gameCommands.Add(Keys.J, jumpPress);
            _gameCommands.Add(Keys.X, jumpPress);
            _gameCommands.Add(Keys.K, actionPress);
            _gameCommands.Add(Keys.Z, actionPress);
            _gameCommands.Add(Keys.V, toggleVaria);
            _gameCommands.Add(Keys.M, toggleMissile);
            _gameCommands.Add(Keys.Escape, pauseGame);
            _gameCommands.Add(Keys.F, fullScreen);
            _gameCommands.Add(Keys.P, cheatUpgrades);

            _menuCommands.Add(Keys.F, fullScreen);
            _menuCommands.Add(Keys.Space, menuSelect);
            _menuCommands.Add(Keys.Enter, menuSelect);
            _menuCommands.Add(Keys.Q, quit);
            _menuCommands.Add(Keys.Up, moveCursorUp);
            _menuCommands.Add(Keys.W, moveCursorUp);
            _menuCommands.Add(Keys.Down, moveCursorDown);
            _menuCommands.Add(Keys.S, moveCursorDown);
            _menuCommands.Add(Keys.J, menuSelect);
            _menuCommands.Add(Keys.X, menuSelect);
            _menuCommands.Add(Keys.A, menuLeft);
            _menuCommands.Add(Keys.Left, menuLeft);
            _menuCommands.Add(Keys.D, menuRight);
            _menuCommands.Add(Keys.Right, menuRight);

            _currentCommands = _menuCommands;
        }
        public ControllerGamepad(Game1 game, int controllerNum)
        {
            _controllerNum = controllerNum;
            Id             = -1;
            ICommandController quit           = new CommandQuit(game);
            ICommandController downPress      = new CommandDownPress();
            ICommandController upPress        = new CommandUpPress();
            ICommandController leftPress      = new CommandLeftPress();
            ICommandController rightPress     = new CommandRightPress();
            ICommandController actionPress    = new CommandActionPress();
            ICommandController jumpPress      = new CommandJumpPress();
            ICommandController toggleVaria    = new CommandToggleVaria();
            ICommandController toggleMissile  = new CommandToggleMissile();
            ICommandController menuSelect     = new CommandMenuSelect(game, this);
            ICommandController pauseGame      = new CommandPauseGame();
            ICommandController moveCursorUp   = new CommandMoveCursorUp();
            ICommandController moveCursorDown = new CommandMoveCursorDown();
            ICommandController menuLeft       = new CommandMenuLeft();
            ICommandController menuRight      = new CommandMenuRight();

            _oldState = GamePad.GetState(0);
            _gameCommands.Add(Buttons.Back, quit);
            _gameCommands.Add(Buttons.LeftThumbstickDown, downPress);
            _gameCommands.Add(Buttons.DPadDown, downPress);
            _gameCommands.Add(Buttons.LeftThumbstickUp, upPress);
            _gameCommands.Add(Buttons.DPadUp, upPress);
            _gameCommands.Add(Buttons.LeftThumbstickLeft, leftPress);
            _gameCommands.Add(Buttons.DPadLeft, leftPress);
            _gameCommands.Add(Buttons.LeftThumbstickRight, rightPress);
            _gameCommands.Add(Buttons.DPadRight, rightPress);
            _gameCommands.Add(Buttons.A, jumpPress);
            _gameCommands.Add(Buttons.X, actionPress);
            _gameCommands.Add(Buttons.LeftTrigger, toggleVaria);
            _gameCommands.Add(Buttons.RightTrigger, toggleMissile);
            _gameCommands.Add(Buttons.Start, pauseGame);

            _menuCommands.Add(Buttons.Start, menuSelect);
            _menuCommands.Add(Buttons.DPadUp, moveCursorUp);
            _menuCommands.Add(Buttons.LeftThumbstickUp, moveCursorUp);
            _menuCommands.Add(Buttons.DPadDown, moveCursorDown);
            _menuCommands.Add(Buttons.LeftThumbstickDown, moveCursorDown);
            _menuCommands.Add(Buttons.Back, quit);
            _menuCommands.Add(Buttons.A, menuSelect);
            _menuCommands.Add(Buttons.DPadLeft, menuLeft);
            _menuCommands.Add(Buttons.LeftThumbstickLeft, menuLeft);
            _menuCommands.Add(Buttons.DPadRight, menuRight);
            _menuCommands.Add(Buttons.LeftThumbstickRight, menuRight);

            _currentCommands = _menuCommands;
        }