Пример #1
0
        protected override void Initialize()
        {
            // Settings
            Settings.Instance.Load();

            Mouse.WindowHandle = Window.Handle;

            IsMouseVisible = true;

            _inputListenerManager = new InputListenerComponent(this);
            Components.Add(_inputListenerManager);

            _mouseListener = new MouseListener();
            _inputListenerManager.Listeners.Add(_mouseListener);

            _mouseListener.MouseMoved += Mouse_MouseMoved;
            _mouseListener.MouseDown  += Mouse_MouseDownOrUp;
            _mouseListener.MouseUp    += Mouse_MouseDownOrUp;

            _gamePadListener = new GamePadListener();
            _inputListenerManager.Listeners.Add(_gamePadListener);

            GamePadListener.CheckControllerConnections   = true;
            GamePadListener.ControllerConnectionChanged += GamePad_ControllerConnectionChanged;

            base.Initialize();
        }
 public GuiInputService(InputListenerComponent inputListener)
 {
     inputListener.Listeners.Add(KeyboardListener = new KeyboardListener());
     inputListener.Listeners.Add(MouseListener    = new MouseListener());
     inputListener.Listeners.Add(GamePadListener  = new GamePadListener());
     inputListener.Listeners.Add(TouchListener    = new TouchListener());
 }
Пример #3
0
 public JoystickPlayerController(Player p)
     : base()
 {
     this.player   = p;
     this.listener = new GamePadListener(new GamePadListenerSettings {
     });
     this.listener.ThumbStickMoved += ThumbStickMoved;
 }
        /// <summary>Initializes a new input capturer using the specified input service</summary>
        /// <param name="inputService">Input service the capturer will subscribe to</param>
        public DefaultInputCapturer(IGuiInputService inputService)
        {
            _inputService  = inputService;
            _inputReceiver = new DummyInputReceiver();

            _keyboardListener = inputService.KeyboardListener;
            _mouseListener    = inputService.MouseListener;
            _gamePadListener  = inputService.GamePadListener;

            SubscribeInputDevices();
        }
Пример #5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();

            scene = titleScene;

            keyboardListener              = new KeyboardListener();
            keyboardListener.KeyReleased += KeyboardListener_KeyReleased;

            gamePadListener           = new GamePadListener();
            gamePadListener.ButtonUp += GamePadListener_ButtonUp;
        }
Пример #6
0
        private void LoadGameAssets()
        {
            new GameStringsLoader(_localizedStringsRepository, _gameCulture);

            _assetsLoader = new AssetsLoader(Content);
            _assetsLoader.LoadResources();
            _mousePointer = _assetsLoader.OtherSprites["manina"];
            _soundManager = new SoundManager(_assetsLoader);

            var gameFactory = new Func <InfartGame>(
                () => new InfartGame(
                    _assetsLoader,
                    _soundManager,
                    _orchestrator,
                    _settingsRepository,
                    _localizedStringsRepository));

            var dialogDefinition = new Rectangle(
                _matrixScaleProvider.VirtualWidth / 2 - 350, 24, 700, _matrixScaleProvider.VirtualHeight - 60);

            var rateMeDialog = new RateMeDialog(
                launchesUntilPrompt: 2,
                maxRateShowTimes: 2,
                rateAppUri: _rateMeUri,
                dialogDefinition: dialogDefinition,
                font: _assetsLoader.Font,
                localizedStringsRepository: _localizedStringsRepository,
                rateMeDialogStrings: _gameCulture.TwoLetterISOLanguageName == "it"
                    ? (RateMeDialogStrings) new DefaultItalianRateMeDialogStrings(GameName)
                    : (RateMeDialogStrings) new DefaultEnglishRateMeDialogStrings(GameName),
                webPageOpener: _webPageOpener,
                settingsRepository: _settingsRepository,
                buttonADefinition: new Rectangle(
                    dialogDefinition.X + 150,
                    dialogDefinition.Y + 350,
                    140, 40),
                buttonBDefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width - 140 - 150,
                    dialogDefinition.Y + 350,
                    140, 40),
                backgroundColor: Color.DarkGray.WithAlpha(1f),
                buttonsBackgroundColor: (new Color(255, 18, 67)).WithAlpha(1f),
                buttonsShadowColor: Color.Black,
                backgroundShadowColor: Color.Black.WithAlpha(1f),
                titleColor: Color.Black,
                buttonsTextColor: new Color(255, 234, 135),
                titlePositionOffset: new Vector2(dialogDefinition.Width / 2, 80f),
                buttonTextPadding: 40f,
                titlePadding: 160f);

            var menuFactory = new Func <MainMenuPage>(
                () => new MainMenuPage(
                    _assetsLoader,
                    rateMeDialog,
                    _soundManager,
                    _matrixScaleProvider,
                    _localizedStringsRepository));

            var scoreFactory = new Func <ScorePage>(
                () => new ScorePage(
                    _assetsLoader,
                    _settingsRepository,
                    _matrixScaleProvider,
                    _localizedStringsRepository));

            _orchestrator = new GameOrchestrator(
                gameFactory,
                menuFactory,
                scoreFactory,
                GraphicsDevice,
                _assetsLoader,
                _settingsRepository,
                _matrixScaleProvider,
                _webPageOpener,
                _localizedStringsRepository);

            _inputListeners = new List <IInputListener>();

            if (_isPc)
            {
                var mouseListener = new MouseListener(_matrixScaleProvider);
                mouseListener.MouseDown += MouseListener_MouseClicked;
                _inputListeners.Add(mouseListener);
            }
            else
            {
                var touchListener = new TouchListener(_matrixScaleProvider);
                touchListener.TouchStarted += TouchListener_TouchEnded;

                var gamepadListener = new GamePadListener();
                gamepadListener.ButtonDown += GamepadListener_ButtonDown;

                _inputListeners.Add(touchListener);
                _inputListeners.Add(gamepadListener);
            }

            var keyboardListener = new KeyboardListener();

            keyboardListener.KeyPressed += KeyboardListener_KeyPressed;
            _inputListeners.Add(keyboardListener);
        }
Пример #7
0
 public void removeListener(GamePadListener gpl)
 {
     _gamePadListeners.Remove(gpl);
 }
Пример #8
0
 public void addListener(GamePadListener gpl)
 {
     _gamePadListeners.AddLast(gpl);
 }
Пример #9
0
 public void AddGamePadListener(GamePadListener listener)
 {
     gamePadListeners.Add(listener);
 }
Пример #10
0
 public void RemoveGamePadListener(GamePadListener listener)
 {
     gamePadListeners.Remove(listener);
 }
Пример #11
0
 public void AddGamePadListener(GamePadListener g)
 {
     if (this.handler != null)
     {
         LInputFactory.AddGamePadListener(g);
     }
 }
Пример #12
0
        private void LoadGameAssets()
        {
            new GameStringsLoader(_localizedStringsRepository, _gameCulture);

            _assetsLoader = new AssetsLoader(
                Content,
                _textFileAssetsLoader);
            _mousePointer = _assetsLoader.Sprites["manina"];
            _soundManager = new SoundManager(_assetsLoader);

            var gameFactory = new Func <RellowGame>(
                () => new RellowGame(
                    _matrixScaleProvider,
                    _assetsLoader,
                    _orchestrator,
                    _soundManager,
                    _settingsRepository,
                    _localizedStringsRepository));

            var dialogDefinition = new Rectangle(
                100, 550, _matrixScaleProvider.VirtualWidth - 200, _matrixScaleProvider.VirtualHeight / 3);
            var rateMeDialog = new RateMeDialog(
                launchesUntilPrompt: 2,
                maxRateShowTimes: 2,
                rateAppUri: _rateMeUri,
                dialogDefinition: dialogDefinition,
                font: _assetsLoader.WritingFont,
                localizedStringsRepository: _localizedStringsRepository,
                rateMeDialogStrings: _gameCulture.TwoLetterISOLanguageName == "it" ? (RateMeDialogStrings) new DefaultItalianRateMeDialogStrings(_gameName) : (RateMeDialogStrings) new DefaultEnglishRateMeDialogStrings(_gameName),
                webPageOpener: _webPageOpener,
                settingsRepository: _settingsRepository,
                buttonADefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 350,
                    500, 100),
                buttonBDefinition: new Rectangle(
                    dialogDefinition.X + dialogDefinition.Width / 2 - 250,
                    dialogDefinition.Y + 500,
                    500, 100),
                backgroundColor: Color.DarkGray.WithAlpha(1f),
                buttonsBackgroundColor: Definitions.PrimaryBackgroundColor.WithAlpha(1f),
                buttonsShadowColor: Color.Black,
                backgroundShadowColor: Color.Black.WithAlpha(1f),
                titleColor: Color.Black,
                buttonsTextColor: Definitions.PrimaryForegroundColor,
                titlePositionOffset: new Vector2(dialogDefinition.Width / 2, 80f),
                buttonTextPadding: 60f,
                titlePadding: 90f);

            var mainMenuFactory = new Func <MainMenuPage>(
                () => new MainMenuPage(
                    _assetsLoader,
                    _orchestrator,
                    _matrixScaleProvider,
                    _localizedStringsRepository,
                    rateMeDialog,
                    _settingsRepository));

            _orchestrator = new GameOrchestrator(
                gameFactory,
                mainMenuFactory,
                GraphicsDevice,
                _matrixScaleProvider,
                _soundManager,
                _webPageOpener);

            _inputListeners = new List <IInputListener>();

            if (_isPc)
            {
                var mouseListener = new MouseListener(_matrixScaleProvider);
                mouseListener.MouseDown += MouseListener_MouseClicked;
                _inputListeners.Add(mouseListener);
            }
            else
            {
                var touchListener = new TouchListener(_matrixScaleProvider);
                touchListener.TouchStarted += TouchListener_TouchEnded;

                var gamepadListener = new GamePadListener();
                gamepadListener.ButtonDown += GamepadListener_ButtonDown;

                _inputListeners.Add(touchListener);
                _inputListeners.Add(gamepadListener);
            }

            // Perchè il back di Android lo prende la tastiera
            var keyboardListener = new KeyboardListener();

            keyboardListener.KeyPressed += KeyboardListener_KeyPressed;
            _inputListeners.Add(keyboardListener);
        }
Пример #13
0
 public void RemoveGamePadListener(GamePadListener listener)
 {
     gamePadListeners.Remove(listener);
 }
Пример #14
0
 public void AddGamePadListener(GamePadListener listener)
 {
     gamePadListeners.Add(listener);
 }
Пример #15
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Window.Title = "Tetris (MonoGame)";
            tetrisBoard  = new TetrisBoard();

            KeyboardListener keyboardListener = new KeyboardListener(new KeyboardListenerSettings());
            GamePadListener  gamePadListener  = new GamePadListener(new GamePadListenerSettings());

            Components.Add(new InputListenerComponent(this, keyboardListener, gamePadListener));

            keyboardListener.KeyPressed += (sender, args) =>
            {
                if (args.Key == Keys.Up && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Rotate();
                }
                else if (args.Key == Keys.Space && !tetrisBoard.IsOver)
                {
                    tetrisBoard.PlaceDown();
                }
                else if (args.Key == Keys.C && !tetrisBoard.IsOver)
                {
                    tetrisBoard.Hold();
                }
                else if (args.Key == Keys.OemMinus)
                {
                    MediaPlayer.Volume -= 0.1f;
                }
                else if (args.Key == Keys.OemPlus)
                {
                    MediaPlayer.Volume += 0.1f;
                }
                else if (args.Key == Keys.M)
                {
                    MediaPlayer.IsMuted = !MediaPlayer.IsMuted;
                }
                else if (args.Key == Keys.R && tetrisBoard.IsOver)
                {
                    tetrisBoard = new TetrisBoard();
                    inTimer     = 500;
                    presses     = 0;
                }
            };

            gamePadListener.ButtonDown += (sender, args) =>
            {
                if (!tetrisBoard.IsOver)
                {
                    if (args.Button == Buttons.DPadUp || args.Button == Buttons.Y)
                    {
                        tetrisBoard.Rotate();
                    }
                    if (args.Button == Buttons.B)
                    {
                        tetrisBoard.PlaceDown();
                    }
                    if (args.Button == Buttons.RightShoulder || args.Button == Buttons.LeftShoulder)
                    {
                        tetrisBoard.Hold();
                    }
                }
            };

            base.Initialize();
        }