Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a new screen manager component.
 /// </summary>
 public ScreenManager(Game game, InputState inputState)
     : base(game)
 {
     input = inputState;
     // we must set EnabledGestures before we can query for them, but
     // we don't assume the game wants to read them.
     TouchPanel.EnabledGestures = GestureType.None;
 }
Ejemplo n.º 2
0
        public override void HandleInput(InputState input)
        {
            // Look up inputs for the active player profile.
            PlayerIndex playerIndex = new PlayerIndex();
            if (input.IsNewKeyPress(Keys.Space, null, out playerIndex))
            {
                onCancel();
            }

            base.HandleInput(input);
        }
Ejemplo n.º 3
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()
        {
            config.Initialize();
            InputState inputState = new InputState(true, config);
            mainCamera = new Camera();
            mainCamera.SubscribeToHandler(inputState);
            // Create the screen manager component.
            screenManager = new ScreenManager(this, inputState);
            graphics.PreferredBackBufferWidth = 1080;
            graphics.PreferredBackBufferHeight = 720;
            //Resolution.Init(ref graphics);
            mainCamera.Init(ref graphics);
            // Change Virtual Resolution
            bool b;
            Point p = config.GetStartUpResolution(out b); //used out to get all three SetRes params
            //Resolution.SetResolution(p.X, p.Y, b);
            mainCamera.SetResolution(p.X, p.Y, b);
            p = config.GetStartUpVResolution();
            //Resolution.SetVirtualResolution(p.X, p.Y);
            mainCamera.InitializeView(p.X, p.Y, 50, 50);

            Content.RootDirectory = "Content";
            Components.Add(screenManager);
            /*
            Components.Add(screenManager);

            // Activate the first screens.
            screenManager.AddScreen(new BackgroundScreen(), null);
            screenManager.AddScreen(new MainMenuScreen(), null);
            */

            base.Initialize();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // Move to the previous menu entry?
            if (input.IsMenuUp(ControllingPlayer))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            // Move to the next menu entry?
            if (input.IsMenuDown(ControllingPlayer))
            {
                selectedEntry++;

                if (selectedEntry >= menuEntries.Count)
                    selectedEntry = 0;
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                OnCancel(playerIndex);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
Ejemplo n.º 7
0
        public void SubscribeToHandler(InputState iState)
        {
            //em.PlaySound += new EventManager.SoundEventHandler(EventFired);
            // lambda expression
            iState.Controls.FireInputEvent  += (sender, firedEvent) =>
            {
                //senders.Add(sender);
                //eventArgs.Add(firedEvent);

                /*
                 * So I wanted this to be quick, a simple switch will check on at most N items,
                 * where N is the number of buttons assigned a command. This should never exceed 20,
                 * mostly because I f*****g say so, but also because even the most complicated RTS or RPG
                 * can be done elegantly so as to not force the player to remember an ungodly amount of
                 * commands. In any case, this area is definitely a candidate for future overhaul pending
                 * future analysis.
                 */
                switch(firedEvent.Command)
                {
                    case Controls.Commands.GameUp :
                        position.Y += (int)scrollSpeedY;
                        //viewPort.Y += (int)scrollSpeedY;
                        //direction = new Vector3(direction.X, direction.Y + (int)scrollSpeedY, 0);
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.GameLeft :
                        position.X += (int)scrollSpeedX;
                        //viewPort.X += (int)scrollSpeedX;
                        //direction = new Vector3(direction.X + (int)scrollSpeedX, direction.Y, 0);
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.GameDown :
                        position.Y -= (int)scrollSpeedY;
                        //viewPort.Y -= (int)scrollSpeedY;
                        //direction = new Vector3(direction.X, direction.Y - (int)scrollSpeedY, 0);
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.GameRight :
                        position.X -= (int)scrollSpeedX;
                        //viewPort.X -= (int)scrollSpeedX;
                        //direction = new Vector3(direction.X - (int)scrollSpeedX, direction.Y, 0);
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.RotateCC:
                        rotation += rotationAmt;
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.RotateCW:
                        rotation -= rotationAmt;
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.Action3:
                        rotation = 0;
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.ZoomIn:
                        SetVirtualResolution(_VWidth + (int)(zoomAmount * getVirtualAspectRatio()), _VHeight + (int)zoomAmount);
                        _dirtyMatrix = true;
                        break;
                    case Controls.Commands.ZoomOut:
                        SetVirtualResolution(_VWidth - (int)(zoomAmount * getVirtualAspectRatio()), _VHeight - (int)zoomAmount);
                        _dirtyMatrix = true;
                        break;
                }

                //if(_dirtyMatrix)

            };
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = (int)ControllingPlayer.Value;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            if (input.IsPauseGame(ControllingPlayer) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(this.game), ControllingPlayer);
            }
            else
            {
                /*
                // Otherwise move the background to scroll
                Vector2 movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.A))
                    movement.X--;

                if (keyboardState.IsKeyDown(Keys.D))
                    movement.X++;

                if (keyboardState.IsKeyDown(Keys.W))
                    movement.Y--;

                if (keyboardState.IsKeyDown(Keys.S))
                    movement.Y++;

                Vector2 thumbstick = gamePadState.ThumbSticks.Left;

                movement.X += thumbstick.X;
                movement.Y -= thumbstick.Y;

                if (movement.Length() > 1)
                    movement.Normalize();

                //playerPosition += movement * 2;
                singlePlayerVP.X += (int)movement.X * 2;
                singlePlayerVP.Y += (int)movement.Y * 2;
                */
            }
        }