Ejemplo n.º 1
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(GameTime gameTime, 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];
            MouseState mouseState = input.CurrentMouseState;
            // 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];

            PlayerIndex player;
            if (pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
            #if WINDOWS_PHONE
                ScreenManager.AddScreen(new PhonePauseScreen(), ControllingPlayer);
            #else
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            #endif
            }
            else
            {
                //Handle Cursor

                if (videoPlayer.State == MediaState.Playing && (keyboardState.IsKeyDown(Keys.E) || keyboardState.IsKeyDown(Keys.Space)))
                {
                    videoPlayer.Stop();
                }

                if (keyboardState.IsKeyDown(Keys.W))
                {
                    //_hero.action(movement, _world);
                }
                if (keyboardState.IsKeyDown(Keys.A))
                {
                    _hero.moveLeft();
                    _camera.EnablePositionTracking = true;
                    if (_debugMode)
                        Console.WriteLine("Hero moving left.");
                }

                if (keyboardState.IsKeyDown(Keys.S))
                {
                    //Not yet implemented.
                }

                if (keyboardState.IsKeyDown(Keys.D))
                {
                    _hero.moveRight();
                    _camera.EnablePositionTracking = true;
                    if (_debugMode)
                        Console.WriteLine("Hero moving right.");
                }

                if (keyboardState.IsKeyDown(Keys.Space) && keyboardState.IsKeyUp(Keys.LeftShift))
                {
                    if (_debugMode)
                        Console.WriteLine("Hero jumping.");
                    _hero.jump();
                    _camera.EnablePositionTracking = true;
                }

                if ((keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift)) &&
                        keyboardState.IsKeyDown(Keys.Space) && (_hero.getSelectedAbility() == AbilityType.GRAVITY_FLIP))
                {
                    _hero.performGravityFlip();
                }

                if (keyboardState.IsKeyDown(Keys.NumPad1) || keyboardState.IsKeyDown(Keys.D1))
                {
                    _hero.selectAbility(AbilityType.NONE);
                    ScreenManager.Game.IsMouseVisible = false;
                }

                if (keyboardState.IsKeyDown(Keys.NumPad2) || keyboardState.IsKeyDown(Keys.D2))
                {
                    _hero.selectAbility(AbilityType.GRAVITY_SPHERE);
                    ScreenManager.Game.IsMouseVisible = true;
                }

                if (keyboardState.IsKeyDown(Keys.NumPad3) || keyboardState.IsKeyDown(Keys.D3))
                {
                    _hero.selectAbility(AbilityType.GRAVITY_HOLE);
                    ScreenManager.Game.IsMouseVisible = true;
                }

                if (keyboardState.IsKeyDown(Keys.NumPad4) || keyboardState.IsKeyDown(Keys.D4))
                {
                    _hero.selectAbility(AbilityType.GRAVITY_FLIP);
                    ScreenManager.Game.IsMouseVisible = false;
                }

                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    _camera.MoveCamera(ConvertUnits.ToSimUnits(new Vector2(-50f, 0f)));
                }
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    _camera.MoveCamera(ConvertUnits.ToSimUnits(new Vector2(50f, 0f)));
                }
                if (keyboardState.IsKeyDown(Keys.Up))
                {
                    _camera.MoveCamera(ConvertUnits.ToSimUnits(new Vector2(0f, -50f)));
                }
                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    _camera.MoveCamera(ConvertUnits.ToSimUnits(new Vector2(0f, 50f)));
                }

                if (keyboardState.IsKeyDown(Keys.LeftControl) || keyboardState.IsKeyDown(Keys.RightControl))
                {
                    if (keyboardState.IsKeyDown(Keys.PageUp))
                    {
                        _camera.Zoom += .05f;
                    }

                    if (keyboardState.IsKeyDown(Keys.PageDown))
                    {
                        _camera.Zoom -= .05f;
                    }

                    if (keyboardState.IsKeyDown(Keys.D0) || keyboardState.IsKeyDown(Keys.NumPad0))
                    {
                        _camera.Zoom = 1f;
                        _camera.Position = _hero.getSimPosition();
                    }

                    if (keyboardState.IsKeyDown(Keys.OemTilde))
                    {
                        //if (!lastKeyboardState.IsKeyDown(Keys.OemTilde))
                        {
                            toggleDebugViewXNA();
                            _debugMode = !_debugMode;
                        }
                        lastKeyboardState = keyboardState;
                    }
                    if (keyboardState.IsKeyDown(Keys.OemPlus))
                    {
                        //if (!lastKeyboardState.IsKeyDown(Keys.OemPlus))
                            loadNextLevel();
                        lastKeyboardState = keyboardState;
                    }
                }

                if (_hero.getSelectedAbility() == AbilityType.GRAVITY_HOLE
                    && input.IsNewMouseButtonPress(MouseButtons.LeftButton))
                {

                    Vector2 position = _camera.ConvertScreenToWorld(input.Cursor);

                    double distance = calculateDistanceOfVectors(position, _hero.getSimPosition());
                    if (distance < 10)
                    {
                        lastMousePosition = position;
                        _hero.performGravityHole(position);
                    }

                    //_hero.setSimPosition(position);

                }
                else if (_hero.getSelectedAbility() == AbilityType.GRAVITY_SPHERE && input.IsNewMouseButtonPress(MouseButtons.LeftButton))
                {

                    Vector2 position = _camera.ConvertScreenToWorld(input.Cursor);
                    clickedPosition = position;

                    double distance = calculateDistanceOfVectors(position, _hero.getSimPosition());
                    Console.WriteLine(distance);
                    //limitting radius
                    if (distance < 10)
                    {
                        _hero.performGravitySphere();

                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void HandleMouseEvents(InputState input)
        {
            Vector2 position = this.Camera.ConvertScreenToWorld(input.Cursor);
            Fixture fix = this.World.TestPoint(position);
            AxiosGameObject gobj;
            if (fix != null && fix.UserData != null && fix.UserData is AxiosGameObject)
            {
                gobj = (AxiosGameObject)fix.UserData;

                if (gobj != null && gobj != prevobj)
                {
                    gobj.OnMouseHover(this, input);

                    if (prevobj != gobj && prevobj != null)
                        prevobj.OnMouseLeave(this, input);
                }
                else if (gobj != null)
                {
                    if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
                    {
                        if (prevobj != null)
                            prevobj.OnFocusLeave(this, input);
                        gobj.OnFocusEnter(this, input);
                        gobj.OnMouseUp(this, input);
                        prevfocusobj = gobj;
                        //prevobj = gobj;
                    }

                    if (input.IsNewMouseButtonPress(MouseButtons.LeftButton))
                        gobj.OnMouseDown(this, input);
                }

                if (gobj != null)
                    prevobj = gobj;
            }
            else
            {
                if (prevobj != null)
                    prevobj.OnMouseLeave(this, input);
                if (input.IsNewMouseButtonPress(MouseButtons.LeftButton) && prevfocusobj != null)
                {
                    prevfocusobj.OnFocusLeave(this, input);
                    prevfocusobj = null;
                }
                prevobj = null;
            }

            Vector2 uiobjpos;
            //Rectangle uirect;
            AxiosRectangle uirect;
            bool foundobject = false;
            Vector2 mousepos = this.Camera.ConvertScreenToWorld(input.Cursor);
            //Vector2 objpos;
            //System.Diagnostics.Debugger.Break();
            AxiosRectangle mousrect = new AxiosRectangle(mousepos.X, mousepos.Y, ConvertUnits.ToSimUnits(25), ConvertUnits.ToSimUnits(25));
            foreach(AxiosUIObject uiobject in _uiobjects)
            {
                uiobjpos = uiobject.Position;
                //objpos = this.Camera.ConvertScreenToWorld(uiobjpos);

                uirect = new AxiosRectangle(ConvertUnits.ToSimUnits(uiobjpos.X), ConvertUnits.ToSimUnits(uiobjpos.Y), ConvertUnits.ToSimUnits(uiobject.Width), ConvertUnits.ToSimUnits(uiobject.Height));

                if (uirect.Intersect(mousrect))
                {

                    if (input.IsNewMouseButtonPress(MouseButtons.LeftButton))
                    {
                        uiobject.OnMouseDown(this, input);
                    }

                    if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
                    {
                        //System.Diagnostics.Debugger.Break();
                        if (prevuifocusobj != uiobject)
                        {
                            uiobject.OnFocusEnter(this, input);
                            if (prevuifocusobj != null)
                                prevuifocusobj.OnFocusLeave(this, input);
                            prevuifocusobj = uiobject;
                        }
                        uiobject.OnMouseUp(this, input);
                    }

                    if (prevuiobj != uiobject)
                    {
                        //System.Diagnostics.Debugger.Break();
                        uiobject.OnMouseHover(this, input);
                        if (prevuiobj != null)
                            prevuiobj.OnMouseLeave(this, input);
                        prevuiobj = uiobject;
                    }
                    foundobject = true;
                    break;

                }
            }
            if (!foundobject && prevuiobj != null)
            {
                //mouse moved away from object
                prevuiobj.OnMouseLeave(this, input);
                prevuiobj = null;
            }

            if (input.IsNewMouseButtonRelease(MouseButtons.LeftButton))
            {
                if (!foundobject && prevuifocusobj != null)
                {

                    prevuifocusobj.OnFocusLeave(this, input);
                    prevuifocusobj = null;
                }
            }
        }
Ejemplo n.º 3
0
 public override void HandleMouseInput(InputState input)
 {
     PlayerIndex player;
     //check for any mouse clicks and select any entries that were clicked
     if (input.IsNewMouseButtonPress(MouseButtons.LeftButton, out player))
     {
         // TODO: Check mouse location
         //Vector2 clickLocation = new Vector2(input.CurrentMouseState.Position.X * ScreenManager.Scaler.Scale.X / (ScreenManager.Game as GoblinsGame.TheGame).ScreenScale, input.CurrentMouseState.Position.Y * ScreenManager.Scaler.Scale.Y / (ScreenManager.Game as GoblinsGame.TheGame).ScreenScale);
         //CheckMenuUnderPoint(clickLocation.ToPoint());
     }
 }
Ejemplo n.º 4
0
        public virtual void HandleCursor(InputState input)
        {
            PlayerIndex player;
            Vector2 position = Camera.ConvertScreenToWorld(input.Cursor);

            if ((input.IsNewButtonPress(Buttons.A, PlayerIndex.One, out player) ||
                    input.IsNewMouseButtonPress(MouseButtons.LeftButton)) &&
                _fixedMouseJoint == null)
            {
                Fixture savedFixture = World.TestPoint(position);
                if (savedFixture != null && savedFixture.UserData is SimpleAxiosGameObject && ((SimpleAxiosGameObject)(savedFixture.UserData)).AllowAutomaticMouseJoint)
                {
                    Body body = savedFixture.Body;
                    _fixedMouseJoint = new FixedMouseJoint(body, position);
                    _fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    World.AddJoint(_fixedMouseJoint);
                    body.Awake = true;
                }
            }

            if ((input.IsNewButtonRelease(Buttons.A, ControllingPlayer.Value, out player) ||
                    input.IsNewMouseButtonRelease(MouseButtons.LeftButton)) &&
                _fixedMouseJoint != null)
            {
                World.RemoveJoint(_fixedMouseJoint);
                _fixedMouseJoint = null;
            }

            if (_fixedMouseJoint != null)
            {
                _fixedMouseJoint.WorldAnchorB = position;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various /// input values for ease of use.
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            PlayerIndex player;

            if (input == null)
                throw new ArgumentNullException("input");

            if (input.IsNewKeyPress(Keys.F12, out player))
            {
                if (!Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().IsFullScreen)
                    Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().TryEnterFullScreenMode();
                else
                    Windows.UI.ViewManagement.ApplicationView
                        .GetForCurrentView().ExitFullScreenMode();
            }

            if (gameOver)
            {
                if (input.IsPauseGame())
                {
                    FinishCurrentGame();
                }

                if (input.IsNewKeyPress(Keys.Space, out player)
                    || input.IsNewKeyPress(Keys.Enter, out player))
                {
                    FinishCurrentGame();
                }

                if (input.IsNewGamePadButtonPress(Buttons.A, out player)
                    || input.IsNewGamePadButtonPress(Buttons.Start, out player))
                {
                    FinishCurrentGame();
                }

                if (input.IsNewMouseButtonPress(MouseButtons.LeftButton,
                                                out player))
                {
                    FinishCurrentGame();
                }

                foreach (GestureSample gestureSample in input.Gestures)
                {
                    if (gestureSample.GestureType == GestureType.Tap)
                    {
                        FinishCurrentGame();
                    }
                }

                return;
            }
        }