示例#1
0
        private void doubleClick(RenderingState renderingState, GameTime time)
        {
            float x = Mouse.GetState().X;
            float y = Mouse.GetState().Y;

            Ray pickRay;

            /*
            * Player wants to do an action.
            * If a firstFactory was not selected, then cannot do anything
            */
            if (firstFactory == null)
                return;

            pickRay = calculateRay(new Vector2(x, y), renderingState);

            StateGameLayer.Factory targeted = calculateTargetedFactory(pickRay, renderingState);

            if (targeted == null)
                return;

            /*Here targeted is not null*/
            if (secondFactory == null)
            {
                /*
                * If here, player has only selected a first factory.
                * Selecting the second factory with a double tap
                * means he wants to attack an enemy factory (type == 2) or defend
                * his own factory (type == 1).
                */

                secondFactory = targeted;
                //secondFactory.Selected = true;

                /*
                 * Player cannot move tropps from and to the same factory
                 */
                if (secondFactory.Equals(firstFactory))
                    return;

                List<StateGameLayer.Factory> order = new List<StateGameLayer.Factory>();
                order.Add(firstFactory);
                order.Add(secondFactory);
                stateGame.state.addOrder(order, 1);

                arrowPosition.Clear();
                arrowPosition.Add(firstFactory.CurrentPos);
                arrowPosition.Add(secondFactory.CurrentPos);

                //firstFactory.Selected = false;
                //firstFactory = null;
                stateGame.state.touchBegin = true;
            }
            else
            {
                /*Double attack*/

                /*
                 * ...else the player has already selected a second factory and
                 * wants to do a double attack or move his troops from
                 * two factories to another one of his.
                 */

                thirdFactory = targeted;
                //thirdFactory.Selected = true;

                /*Player cannot move troops to one of the two selected factories*/
                if (thirdFactory.Equals(firstFactory) || thirdFactory.Equals(secondFactory))
                    return;

                List<StateGameLayer.Factory> order = new List<StateGameLayer.Factory>();
                order.Add(firstFactory);
                order.Add(secondFactory);
                order.Add(thirdFactory);

                stateGame.state.addOrder(order, 1);

                arrowPosition.Clear();
                arrowPosition.Add(firstFactory.CurrentPos);
                arrowPosition.Add(secondFactory.CurrentPos);
                arrowPosition.Add(thirdFactory.CurrentPos);

                //firstFactory.Selected = false;
                //firstFactory = null;

                //secondFactory.Selected = false;
                //secondFactory = null;
            }

            /*
            * If here, player launched a single, or double attack, or
            * moved his troops or double tapped on nothing.
            * Reset.
            */
            if (firstFactory != null)
            {
                firstFactory.Selected = false;
                firstFactory = null;
            }

            if (secondFactory != null)
            {
                secondFactory.Selected = false;
                secondFactory = null;
            }

            if (thirdFactory != null)
            {
                thirdFactory.Selected = false;
                thirdFactory = null;
            }

            stateGame.state.touchBegin = true;
        }
示例#2
0
        private void singleClick(RenderingState renderingState, GameTime time)
        {
            float x = Mouse.GetState().X;
            float y = Mouse.GetState().Y;

            Ray pickRay;

            if (renderingState.speedBonusRect.Contains(
                new Point((int)x, (int)y)))
            {

                /*
                 * Player clicked on the speed bonus.
                 */
                manageBonus(0, renderingState);
                return;
            }

            if (renderingState.freezeBonusRect.Contains(
                new Point((int)x, (int)y)))
            {
                /*
                 * Player clicked on the attack bonus
                 */
                manageBonus(1, renderingState);
                return;

            }

            if (renderingState.halfFactoryBonusRect.Contains(
                new Point((int)x, (int)y)))
            {
                /*
                 * Player clicked on the shield bonus
                 */
                manageBonus(2, renderingState);
                return;

            }

            if (renderingState.armageddonBonusRect.Contains(
            new Point((int)x, (int)y)))
            {
                manageBonus(3, renderingState);
                return;
            }

            StateGameLayer.Factory targeted = null;

            pickRay = calculateRay(new Vector2(x, y), renderingState);

            targeted = calculateTargetedFactory(pickRay, renderingState);

            if (targeted != null && targeted.ObjectType == 1)
            {
                /*
                * ...player selected the factory "targeted".
                * If here, "targeted" is property of player. A player
                * can only select his own factories (type == 1).
                * If firstFactory is null, this is the first factory
                * the player selected.
                */
                if (firstFactory == null)
                {
                    firstFactory = targeted;
                    firstFactory.Selected = true;
                    firstFactory.selectionSound = true;
                }
                else
                {
                    /*
                     * ...else this is the second factory.
                     * Player can only double select his own factories.
                     * Cannot select: firstFactory and an enemy factory.
                     * Cannot select: firstFactory and a neutral factory.
                     */

                    /*
                     * Player maybe have already tapped a second factory and
                     * selects another secondFactory. Reset previous secondFactory.
                     */
                    if (secondFactory != null)
                        secondFactory.Selected = false;

                    secondFactory = targeted;
                    if (secondFactory.ObjectType == 1)
                    {
                        secondFactory.Selected = true;
                        secondFactory.selectionSound = true;
                    }
                    else
                    {
                        secondFactory.Selected = false;
                        secondFactory = null;
                    }
                }

                return;
            }

            /*
            * If here, player targeted an enemy or neutral factory.
            * Or maybe player tapped on nothing (no collision).
            * Reset.
            */
            if (firstFactory != null)
            {
                firstFactory.Selected = false;
                firstFactory = null;
            }

            if (secondFactory != null)
            {
                secondFactory.Selected = false;
                secondFactory = null;
            }

            if (thirdFactory != null)
            {
                thirdFactory.Selected = false;
                thirdFactory = null;
            }
        }
示例#3
0
        public void UpdateInput(RenderingState renderingState, GameTime time)
        {
            while (TouchPanel.IsGestureAvailable)
            {
                var touchGesture = TouchPanel.ReadGesture();
                Ray pickRay;

                switch (touchGesture.GestureType)
                {
                    /*
                     * Single tap select a factory
                     */
                    case GestureType.Tap:
                        {
                            if (stateGame.state.enabled)
                            {
                                if (renderingState.speedBonusRect.Contains(
                                    new Point((int)touchGesture.Position.X, (int)touchGesture.Position.Y)))
                                {
                                    /*
                                     * Player clicked on the speed bonus.
                                     */
                                    manageBonus(0, renderingState);
                                    return;
                                }

                                if (renderingState.freezeBonusRect.Contains(
                                    new Point((int)touchGesture.Position.X, (int)touchGesture.Position.Y)))
                                {
                                    /*
                                     * Player clicked on the attack bonus
                                     */
                                    manageBonus(1, renderingState);
                                    return;
                                }

                                if (renderingState.halfFactoryBonusRect.Contains(
                                    new Point((int)touchGesture.Position.X, (int)touchGesture.Position.Y)))
                                {
                                    /*
                                     * Player clicked on the shield bonus
                                     */
                                    manageBonus(2, renderingState);
                                    return;
                                }

                                if (renderingState.armageddonBonusRect.Contains(
                                new Point((int)touchGesture.Position.X, (int)touchGesture.Position.Y)))
                                {
                                    manageBonus(3, renderingState);
                                    return;
                                }

                                StateGameLayer.Factory targeted = null;

                                pickRay = calculateRay(new Vector2(touchGesture.Position.X, touchGesture.Position.Y), renderingState);

                                targeted = calculateTargetedFactory(pickRay, renderingState);

                                if (targeted != null && targeted.ObjectType == 1)
                                {
                                    /*
                                    * ...player selected the factory "targeted".
                                    * If here, "targeted" is property of player. A player
                                    * can only select his own factories (type == 1).
                                    * If firstFactory is null, this is the first factory
                                    * the player selected.
                                    */
                                    if (firstFactory == null)
                                    {
                                        firstFactory = targeted;
                                        firstFactory.Selected = true;
                                        firstFactory.selectionSound = true;
                                    }
                                    else
                                    {
                                        /*
                                         * ...else this is the second factory.
                                         * Player can only double select his own factories.
                                         * Cannot select: firstFactory and an enemy factory.
                                         * Cannot select: firstFactory and a neutral factory.
                                         */

                                        /*
                                         * Player maybe have already tapped a second factory and
                                         * selects another secondFactory. Reset previous secondFactory.
                                         */
                                        if (secondFactory != null)
                                            secondFactory.Selected = false;

                                        secondFactory = targeted;
                                        if (secondFactory.ObjectType == 1)
                                        {
                                            secondFactory.Selected = true;
                                            secondFactory.selectionSound = true;
                                        }
                                        else
                                        {
                                            secondFactory.Selected = false;
                                            secondFactory = null;
                                        }
                                    }

                                    return;
                                }

                                /*
                                * If here, player targeted an enemy or neutral factory.
                                * Or maybe player tapped on nothing (no collision).
                                * Reset.
                                */
                                if (firstFactory != null)
                                {
                                    firstFactory.Selected = false;
                                    firstFactory = null;
                                }

                                if (secondFactory != null)
                                {
                                    secondFactory.Selected = false;
                                    secondFactory = null;
                                }

                                if (thirdFactory != null)
                                {
                                    thirdFactory.Selected = false;
                                    thirdFactory = null;
                                }
                            }
                        }
                        if (renderingState.pauseButton.Contains(
                        new Point((int)touchGesture.Position.X, (int)touchGesture.Position.Y)))
                        {
                            /*
                            * Player clicked on pause button
                            */
                            if (stateGame.state.enabled)
                                stop();
                            else
                                start();

                            return;
                        }
                        break;

                    /*
                     * Double tap to do an action
                     */
                    case GestureType.Hold:
                        {
                            if (stateGame.state.enabled)
                            {
                                /*
                                * Player wants to do an action.
                                * If a firstFactory was not selected, then cannot do anything
                                */
                                if (firstFactory == null)
                                    return;

                                pickRay = calculateRay(new Vector2(touchGesture.Position.X, touchGesture.Position.Y), renderingState);

                                StateGameLayer.Factory targeted = calculateTargetedFactory(pickRay, renderingState);

                                if (targeted == null)
                                    return;

                                /*Here targeted is not null*/
                                if (secondFactory == null)
                                {
                                    /*
                                    * If here, player has only selected a first factory.
                                    * Selecting the second factory with a double tap
                                    * means he wants to attack an enemy factory (type == 2) or defend
                                    * his own factory (type == 1).
                                    */

                                    secondFactory = targeted;
                                    //secondFactory.Selected = true;

                                    /*
                                     * Player cannot move tropps from and to the same factory
                                     */
                                    if (secondFactory.Equals(firstFactory))
                                        return;

                                    List<StateGameLayer.Factory> order = new List<StateGameLayer.Factory>();
                                    order.Add(firstFactory);
                                    order.Add(secondFactory);
                                    stateGame.state.addOrder(order, 1);

                                    arrowPosition.Clear();
                                    arrowPosition.Add(firstFactory.CurrentPos);
                                    arrowPosition.Add(secondFactory.CurrentPos);

                                    stateGame.state.touchBegin = true;
                                }
                                else
                                {
                                    /*Double attack*/

                                    /*
                                     * ...else the player has already selected a second factory and
                                     * wants to do a double attack or move his troops from
                                     * two factories to another one of his.
                                     */

                                    thirdFactory = targeted;
                                    //thirdFactory.Selected = true;

                                    /*Player cannot move troops to one of the two selected factories*/
                                    if (thirdFactory.Equals(firstFactory) || thirdFactory.Equals(secondFactory))
                                        return;

                                    List<StateGameLayer.Factory> order = new List<StateGameLayer.Factory>();
                                    order.Add(firstFactory);
                                    order.Add(secondFactory);
                                    order.Add(thirdFactory);

                                    stateGame.state.addOrder(order, 1);

                                    arrowPosition.Clear();
                                    arrowPosition.Add(firstFactory.CurrentPos);
                                    arrowPosition.Add(secondFactory.CurrentPos);
                                    arrowPosition.Add(thirdFactory.CurrentPos);
                                }

                                /*
                                * If here, player launched a single, or double attack, or
                                * moved his troops or double tapped on nothing.
                                * Reset.
                                */
                                if (firstFactory != null)
                                {
                                    firstFactory.Selected = false;
                                    firstFactory = null;
                                }

                                if (secondFactory != null)
                                {
                                    secondFactory.Selected = false;
                                    secondFactory = null;
                                }

                                if (thirdFactory != null)
                                {
                                    thirdFactory.Selected = false;
                                    thirdFactory = null;
                                }

                                stateGame.state.touchBegin = true;
                            }
                        }
                        break;

                    case GestureType.Pinch:
                        {
                            float distance;

                            Vector2 firstFinger = new Vector2(touchGesture.Delta.X, touchGesture.Delta2.Y);
                            Vector2 secondFinger = new Vector2(touchGesture.Delta2.X, touchGesture.Delta2.Y);

                            distance = Vector2.Distance(firstFinger, secondFinger);

                            if (stateGame.state.previousDistance == null)
                                stateGame.state.previousDistance = distance;

                            if (distance < stateGame.state.previousDistance)
                            {
                                /*Aumenta il fieldOfVIew*/
                                renderingState.zoomOut();
                            }
                            else
                                renderingState.zoomIn();
                        }
                        break;

                    case GestureType.FreeDrag:
                        {
                            if (stateGame.state.enabled)
                            {
                                float speedOfDragging = 7.8f;
                                if (stateGame.state.dragging.Count < 2)
                                {
                                    stateGame.state.dragging.Add(new Vector2(touchGesture.Position.X, touchGesture.Position.Y));
                                }
                                else
                                {
                                    /*If here, 2 drag position*/
                                    float x = stateGame.state.dragging[0].X - stateGame.state.dragging[1].X;

                                    /*Calc the Z translation (Z for the world, Y for the touchscreen*/
                                    float z = stateGame.state.dragging[0].Y - stateGame.state.dragging[1].Y;

                                    /*See you.*/
                                    renderingState.TranslateX(x * speedOfDragging);
                                    renderingState.TranslateZ(z * speedOfDragging);

                                    /*Remove the ancient position*/
                                    stateGame.state.dragging.RemoveAt(0);
                                }
                            }
                        }
                        break;

                    case GestureType.DragComplete:
                        /*Reset info about dragging*/
                        stateGame.state.dragging.Clear();
                        break;
                }

            }
        }