Example #1
0
        Vector2 GetDesireVelocityFromInput()
        {
            Vector2 desireVelocity = new Vector2();

            TouchCollection touchCollection = TouchPanel.GetState();

            if (touchCollection.Count > 0)
            {
                desireVelocity.X = touchCollection.First().Position.X - X;
                desireVelocity.Y = touchCollection.First().Position.Y - Y;

                if (desireVelocity.X != 0 || desireVelocity.Y != 0)
                {
                    desireVelocity.Normalize();
                    const float desiredSpeed = 200;
                    desireVelocity *= desiredSpeed;
                }
            }

            return(desireVelocity);
        }
Example #2
0
        private void HandleTouches()
        {
            TouchCollection touches = TouchPanel.GetState();

            if (!_touching && touches.Count > 0)
            {
                _touching = true;

                //create a bullet
                //send the bullet to the target
                var touch  = touches.First();
                var bullet = new Bullet(this, _bulletTexture, new Vector2(_ship.Position.X - _ship.Radius, _ship.Position.Y), touch.Position);

                _bullets.Add(bullet);

                //Rotate ship towards touch position
                _ship.RotateTowards(touch.Position);
            }
            else if (touches.Count == 0)
            {
                _touching = false;
            }
        }
        //------------------------------------------------------------------
        public void UpdateTouch()
        {
            UpdateMouse();

            //Get the state of the touch panel
            TouchCollection touches = TouchPanel.GetState();

            // ToDo: Only first Touch?
            // Handle only first Touch
            if (!touches.Any())
            {
                return;
            }

            var first = touches.First();

            if (first.State == TouchLocationState.Pressed)
            {
                HandleTouch(first.Position);
            }

//            // Process touch locations
//            foreach (TouchLocation location in curTouches)
//            {
//                switch (location.State)
//                {
//                    case TouchLocationState.Pressed:
//                        HandleTouch (location.Position);
//                        break;
//                    case TouchLocationState.Released:
//                        break;
//                    case TouchLocationState.Moved:
//                        break;
//                }
//            }
        }
        public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState)
        {
            if (currentTouch.Count != 1)
            {
                nextState = new CooldownState();
                TouchStateMachine.SubmitGestureEvent(new DragEventArgs(GestureTiming.Completed, new Vector2()));
                return(true);
            }

            TouchStateMachine.SubmitGestureEvent(new DragEventArgs(GestureTiming.InProgress, currentTouch.First().Position));
            nextState = null;
            return(false);
        }
Example #5
0
        public static void update(bool game_active, GameTime gameTime,
                                  KeyboardState key_state, GamePadState controller_state)
        {
            PlayerInputs = InputConfig.Update(PlayerInputs, key_state, controller_state);

            LastMouseState = MouseState;
            MouseState     = Mouse.GetState();
#if TOUCH_EMULATION
            //The TouchPanel needs to know the time for when touches arrive
            TouchPanelState.CurrentTimestamp = gameTime.TotalGameTime;

            Vector2 posThisFrame = new Vector2(MouseState.X, MouseState.Y);
            Vector2 posLastFrame = new Vector2(LastMouseTouchState.X, LastMouseTouchState.Y);

            simulate_touch(MouseState.LeftButton, LastMouseTouchState.LeftButton,
                           posThisFrame, posLastFrame, false);
            simulate_touch(MouseState.RightButton, LastMouseTouchState.RightButton,
                           posThisFrame, posLastFrame, true);

            LastMouseTouchState = MouseState;
            MouseState          = new MouseState();
#endif

            ControlSchemeSwitched = false;

#if __MOBILE__ || TOUCH_EMULATION
            _touchCollection = TouchPanel.GetState();
            Gestures.Clear();
            while (TouchPanel.IsGestureAvailable)
            {
                var gesture = TouchPanel.ReadGesture();
                Gestures.Add(gesture);
            }

#if CONTROL_MOUSE_WITH_TOUCH
            MouseState = new MouseState(
                (int)(Config.WINDOW_WIDTH * ScreenScaleZoom.X / 2),
                (int)(Config.WINDOW_HEIGHT * ScreenScaleZoom.Y / 2), 0,
                ButtonState.Released,
                ButtonState.Released, ButtonState.Released,
                ButtonState.Released, ButtonState.Released);
            if (_touchCollection.Count != 0)
            {
                if (GameActive)
                {
                    if (ControlScheme != ControlSchemes.Mouse)
                    {
                        ControlSchemeSwitched = true;
                    }
                    ControlScheme = ControlSchemes.Mouse;
                }

                TouchLocation touch = _touchCollection.First();
                MouseState = new MouseState(
                    (int)touch.Position.X,
                    (int)touch.Position.Y, 0,
                    touch.State == TouchLocationState.Released ?
                    ButtonState.Released : ButtonState.Pressed,
                    ButtonState.Released, ButtonState.Released,
                    ButtonState.Released, ButtonState.Released);
            }
#endif
#endif

            update_control_scheme(key_state, controller_state);

            GameActive = game_active;

            update_mouse_button_hold();
            update_mouse_click_locs();

            update_controller_active(key_state, controller_state);
        }
Example #6
0
        /// <summary>
        /// Handle user touch events: Pressed, Moved, Released
        /// </summary>
        private void handleTouch()
        {
            // Handle all touch here
            TouchCollection touchCollection = TouchPanel.GetState();

            if (touchCollection.Count() > 0)
            {
                TouchLocation tl = touchCollection.First();

                if (tl.State == TouchLocationState.Pressed)
                {
                    // Handle deck touch and find active card
                    Card ret = null;
                    for (int di = 0; di < m_deckList.Count; di++)
                    {
                        ret = m_deckList[di].HandleTouch(tl);
                        if (ret != null)
                        {
                            break;
                        }
                    }
                    // Accept to select cards?
                    if (ret != null && ret.OwnerDeck.Type() != Deck.DeckType.ESourceDeck)
                    {
                        // Turn card and activate
                        if (!ret.IsTurned())
                        {
                            if (ret.ParentCard == null)
                            {
                                ret.setTurned(true);
                                p_activeCard = ret;
                            }
                        }
                        // Car is turned
                        // Set active card under move
                        else
                        {
                            p_activeCard = ret;
                        }
                    }
                }
                else if (tl.State == TouchLocationState.Moved)
                {
                    // If active card, move it
                    if (p_activeCard != null)
                    {
                        p_activeCard.handleTouch(tl);
                    }
                }
                else if (tl.State == TouchLocationState.Released)
                {
                    // Where active card was released?
                    if (p_activeCard != null)
                    {
                        // Accept moving cards only from target and source decks
                        Deck fromDeck = p_activeCard.OwnerDeck;
                        if (fromDeck != null && (fromDeck.Type() == Deck.DeckType.EUserDeck ||
                                                 fromDeck.Type() == Deck.DeckType.EWasteDeck))
                        {
                            // Find deck where card was released, accept target and source decks only
                            Deck toDeck = GetDeckUnderTouch(tl);
                            if (toDeck != null && (toDeck.Type() == Deck.DeckType.EUserDeck ||
                                                   toDeck.Type() == Deck.DeckType.ETargetDeck))
                            {
                                if (toDeck == fromDeck)
                                {
                                    // cancel move
                                    p_activeCard.cancelMove();
                                }
                                else
                                {
                                    // Check is this card move acceptable
                                    if (isAcceptedMove(p_activeCard, toDeck))
                                    {
                                        // Accept move
                                        fromDeck.RemoveCard(p_activeCard);
                                        toDeck.AddCard(p_activeCard);
                                    }
                                    else
                                    {
                                        // Cancel move
                                        p_activeCard.cancelMove();
                                    }
                                }
                            }
                            else
                            {
                                // Trying to move card between not acceptable decks
                                p_activeCard.cancelMove();
                            }
                        }
                        else
                        {
                            // Trying to move card between not acceptable decks
                            p_activeCard.cancelMove();
                        }
                        // Reset active card, no moving ongoing
                        p_activeCard = null;
                    }


                    int count = 0;
                    for (int i = 0; i < m_deckList.Count(); i++)
                    {
                        count += m_deckList[i].CardCount();
                    }
                }
            }
        }