Пример #1
0
        public void HandleInput(GestureSample gestureSample)
        {
            // Process input only if in Human's turn
            if (IsActive)
            {
                // Process any Drag gesture
                if (gestureSample.GestureType == GestureType.FreeDrag)
                {
                    // If drag just began, save the sample for future
                    // calculations and start Aim "animation"
                    if (null == firstSample)
                    {
                        firstSample           = gestureSample;
                        Catapult.CurrentState = CatapultState.Aiming;
                    }

                    // save the current gesture sample
                    prevSample = gestureSample;

                    // calculate the delta between first sample and current
                    // sample to present visual sound on screen
                    Vector2 delta = prevSample.Value.Position -
                                    firstSample.Value.Position;
                    Catapult.ShotStrength = delta.Length() / maxDragDelta;
                    float baseScale = 0.001f;
                    arrowScale = baseScale * delta.Length();
                    isDragging = true;
                }
                else if (gestureSample.GestureType == GestureType.DragComplete)
                {
                    // calculate velocity based on delta between first and last
                    // gesture samples
                    if (null != firstSample)
                    {
                        Vector2 delta = prevSample.Value.Position -
                                        firstSample.Value.Position;
                        Catapult.ShotVelocity = MinShotStrength +
                                                Catapult.ShotStrength *
                                                (MaxShotStrength - MinShotStrength);
                        Catapult.Fire(Catapult.ShotVelocity);
                        Catapult.CurrentState = CatapultState.Firing;
                    }

                    // turn off dragging state
                    ResetDragState();
                }
            }
        }
Пример #2
0
        public void HandleInput(InputState input)
        {
            // Process input only if in Human's turn
            if (IsActive && !IsAI)
            {
                if (input.MouseGesture.HasFlag(MouseGestureType.FreeDrag))
                {
                    // If drag just began save the sample for future
                    // calculations and start Aim "animation"
                    if (null == firstMouseSample)
                    {
                        firstMouseSample      = input.MouseDragStartPosition;
                        Catapult.CurrentState = CatapultState.Aiming;
                    }

                    // save the current gesture sample
                    prevMouseSample = input.CurrentMousePosition;

                    // calculate the delta between first sample and current
                    // sample to present visual sound on screen
                    Vector2 delta = (Vector2)prevMouseSample - (Vector2)firstMouseSample;
                    Catapult.ShotStrength = delta.Length() / maxDragDelta;
                    float baseScale = 0.001f;
                    arrowScale = baseScale * delta.Length();
                    isDragging = true;
                }
                else if (input.MouseGesture.HasFlag(MouseGestureType.DragComplete))
                {
                    // calc velocity based on delta between first and last
                    // gesture samples
                    if (null != firstMouseSample)
                    {
                        Vector2 delta = (Vector2)prevMouseSample - (Vector2)firstMouseSample;
                        Catapult.ShotVelocity = MinShotStrength + Catapult.ShotStrength *
                                                (MaxShotStrength - MinShotStrength);
                        Catapult.Fire(Catapult.ShotVelocity);
                        Catapult.CurrentState = CatapultState.Firing;
                    }

                    ResetDragState();
                }
            }
        }