/// <summary>
        /// Updates the current formation to the newly recognized system gesture.
        /// </summary>
        public void UpdateFormation()
        {
            //If the player is triggering a fusion
            if (Defines.playerFusionTriggered[this.currentPlayerIndex])
            {
                //If there is a second player and that player is also in fusion mode
                if (Defines.playersGestures.Count > 1)
                {
                    //Get the index of the other player
                    PlayerIndex _otherPlayer = (this.currentPlayerIndex == PlayerIndex.One) ? PlayerIndex.Two : PlayerIndex.One;

                    //If the other player is in fusion mode and their formation isn't a Normal formation
                    if (Defines.playerFusionTriggered[_otherPlayer])
                    {
                        //Check the ID of the gesture
                        switch (currentFormationID)
                        {
                        case Defines.GESTURES.LINE:
                            currentFormationID = Defines.GESTURES.LINE_FUSION;
                            break;

                        case Defines.GESTURES.SQUARE:
                            currentFormationID = Defines.GESTURES.SQUARE_FUSION;
                            break;

                        case Defines.GESTURES.TRIANGLE:
                            currentFormationID = Defines.GESTURES.TRIANGLE_FUSION;
                            break;

                        case Defines.GESTURES.V:
                            currentFormationID = Defines.GESTURES.V_FUSION;
                            break;
                        }
                        currentFusionFormation = fusionFormationList[currentFormationID];

                        //Set the current formation to the fusion formation for this player
                        currentFormation = currentFusionFormation.playerFormationList[currentPlayerIndex];
                        //Set up the formation manager for a fusion formation.
                        this.StartFusionMode();
                    }
                }
                //Otherwise we need a single-player fusion mode.
                else if (Defines.playersGestures.Count == 1)
                {
                    //TODO: Implement single-player fusion triggering.
                }
            }
            //Otherwise, we're not triggering a fusion,
            //  so just find the regular formation
            else
            {
                currentFormation = formationList[currentFormationID];
            }

            //Set ID to remember gesture
            previousFormationID = currentFormationID;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime, int numShips, Vector2 fixedPoint)
        {
            //Store the changed fixed point
            globalFixedPoint = fixedPoint;

            /*
             * Note: We only want to check for new formation changes when we aren't
             * in fusion mode. If we are in fusion mode, then we check for formations when
             * the fusion timer has expired.
             */
            if (!inFusionMode)
            {
                //Update the gesture component to check for new formations
                gestureComponent.Update(gameTime);

                //Check for new gestures
                currentFormationID = gestureComponent.currentShape;
                if (currentFormationID != previousFormationID)
                {
                    //Update formation positions
                    UpdateFormation();
                }

                //Update the positions of the ships based on the player's fixed point
                currentFormation.Update(gameTime, numShips, globalFixedPoint);
            }
            //Otherwise, we're in a fusion formation
            else
            {
                //Only player one can manipulate the global fusion timer
                if (currentPlayerIndex == PlayerIndex.One)
                {
                    Defines.FusionTimer -= gameTime.ElapsedGameTime;
                }

                if (Defines.FusionTimer <= TimeSpan.Zero)
                {
                    inFusionMode = false;
                }

                currentFusionFormation.Update(gameTime, globalFixedPoint);
                currentFormation = currentFusionFormation.playerFormationList[currentPlayerIndex];
            }
        }
Beispiel #3
0
        public void Update(GameTime gameTime, GamePadState currentState)
        {
            UpdateInput(gameTime, currentState);

            //Update the formation manager to check for new formations
            formationManager.Update(gameTime, numActiveShips, fixedPoint);

            //Update our global fusion mode flag
            Defines.playerFusionTriggered[this.currentPlayerIndex] = formationManager.gestureComponent.fusionGestureMode;

            //If the formation manager set a new formation
            if (curFormation.ID != formationManager.currentFormation.ID)
            {
                changedFormations = true;
                //Change our new current formation
                curFormation = formationManager.currentFormation;
                //Update our global formation/gesture
                Defines.playersGestures[this.currentPlayerIndex] = curFormation.ID;
                this.interpTimeSoFar = TimeSpan.Zero;
            }

            this.UpdateShips(gameTime);
        }
        /// <summary>
        /// Creates all of the games formation objects with ship 
        /// pre-defined positions based on the number of ships to be used.
        /// </summary>
        /// <param name="numShips">The number of ships that will be used within the formations.</param>
        /// <param name="shipWidth">The width of the ship that will be used in spacing the ships.</param>
        /// <param name="shipHeight">The height of the ship that will be used in spacing the ships.</param>
        public FormationManager(Game game, int numShips, int shipWidth, int shipHeight, PlayerIndex playerIndex)
        {
            this.game = game;
            this.currentPlayerIndex = playerIndex;

            currentNumberOfShips = numShips;
            globalFixedPoint = Vector2.Zero;
            drawFixedPoint = false;

            //Initialize the global fixed point to the bottom middle of the screen.
            globalRotation = 0;

            /* Initialize the different formations (positions, rotations, and bounding rectangles) */
            formationList = new Dictionary<Defines.GESTURES,Formation>();

            //TODO: Stop using the formation variables and just populate the formation list.
            formationList.Add(Defines.GESTURES.NORMAL, new NormalFormation(numShips, shipWidth, shipHeight, globalFixedPoint));
            formationList.Add(Defines.GESTURES.SQUARE, new SquareFormation(numShips, shipWidth, shipHeight, globalFixedPoint));
            formationList.Add(Defines.GESTURES.V, new VFormation(numShips, shipWidth, shipHeight, globalFixedPoint));
            formationList.Add(Defines.GESTURES.LINE, new LineFormation(numShips, shipWidth, shipHeight, globalFixedPoint));
            formationList.Add(Defines.GESTURES.TRIANGLE, new TriangleFormation(numShips, shipWidth, shipHeight, globalFixedPoint));
            formationList.Add(Defines.GESTURES.RESET, formationList[Defines.GESTURES.NORMAL]);

            fusionFormationList = new Dictionary<Defines.GESTURES, FusionFormation>();
            fusionFormationList.Add(Defines.GESTURES.LINE_FUSION, new CrossFusionFormation(game, shipWidth, shipHeight, globalFixedPoint));

            //Set current formation to the default Normal Formation.
            currentFormation = formationList[Defines.GESTURES.NORMAL];
            gestureComponent = new GestureComponent(playerIndex);
        }
        /// <summary>
        /// Updates the current formation to the newly recognized system gesture.
        /// </summary>
        public void UpdateFormation()
        {
            //If the player is triggering a fusion
            if (Defines.playerFusionTriggered[this.currentPlayerIndex])
            {
                //If there is a second player and that player is also in fusion mode
                if (Defines.playersGestures.Count > 1)
                {
                    //Get the index of the other player
                    PlayerIndex _otherPlayer = (this.currentPlayerIndex == PlayerIndex.One) ? PlayerIndex.Two : PlayerIndex.One;

                    //If the other player is in fusion mode and their formation isn't a Normal formation
                    if (Defines.playerFusionTriggered[_otherPlayer])
                    {
                        //Check the ID of the gesture
                        switch (currentFormationID)
                        {
                            case Defines.GESTURES.LINE:
                                currentFormationID = Defines.GESTURES.LINE_FUSION;
                                break;
                            case Defines.GESTURES.SQUARE:
                                currentFormationID = Defines.GESTURES.SQUARE_FUSION;
                                break;
                            case Defines.GESTURES.TRIANGLE:
                                currentFormationID = Defines.GESTURES.TRIANGLE_FUSION;
                                break;
                            case Defines.GESTURES.V:
                                currentFormationID = Defines.GESTURES.V_FUSION;
                                break;
                        }
                        currentFusionFormation = fusionFormationList[currentFormationID];

                        //Set the current formation to the fusion formation for this player
                        currentFormation = currentFusionFormation.playerFormationList[currentPlayerIndex];
                        //Set up the formation manager for a fusion formation.
                        this.StartFusionMode();
                    }

                }
                //Otherwise we need a single-player fusion mode.
                else if (Defines.playersGestures.Count == 1)
                {
                    //TODO: Implement single-player fusion triggering.
                }

            }
            //Otherwise, we're not triggering a fusion,
            //  so just find the regular formation
            else
                currentFormation = formationList[currentFormationID];

            //Set ID to remember gesture
            previousFormationID = currentFormationID;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime, int numShips, Vector2 fixedPoint)
        {
            //Store the changed fixed point
            globalFixedPoint = fixedPoint;

            /*
             * Note: We only want to check for new formation changes when we aren't
             * in fusion mode. If we are in fusion mode, then we check for formations when
             * the fusion timer has expired.
             */
            if (!inFusionMode)
            {
                //Update the gesture component to check for new formations
                gestureComponent.Update(gameTime);

                //Check for new gestures
                currentFormationID = gestureComponent.currentShape;
                if (currentFormationID != previousFormationID)
                    //Update formation positions
                    UpdateFormation();

                //Update the positions of the ships based on the player's fixed point
                currentFormation.Update(gameTime, numShips, globalFixedPoint);

            }
            //Otherwise, we're in a fusion formation
            else
            {
                //Only player one can manipulate the global fusion timer
                if(currentPlayerIndex == PlayerIndex.One)
                    Defines.FusionTimer -= gameTime.ElapsedGameTime;

                if (Defines.FusionTimer <= TimeSpan.Zero)
                    inFusionMode = false;

                currentFusionFormation.Update(gameTime, globalFixedPoint);
                currentFormation = currentFusionFormation.playerFormationList[currentPlayerIndex];
            }
        }
        public ShipManager(Game game, PlayerIndex playerIndex)
        {
            shipList = new List<Gryffon>();
            numShips = 4;
            numActiveShips = numShips;
            currentPlayerIndex = playerIndex;
            //Initialize ships
            for (int i = 0; i < numShips; i++)
            {
                //Put ships into a default (no) formation
                shipList.Add(new Gryffon(Vector2.Zero, game));
                shipList[i].rotateAboutFixedPoint = true;
                shipList[i].color = (currentPlayerIndex == PlayerIndex.One) ? Color.PowderBlue : Color.Red;
            }

            formationManager = new FormationManager(game, numShips,
                shipList[0].texture.Width,
                shipList[0].texture.Height,
                currentPlayerIndex);

            //Set the default location of the fixed point
            fixedPoint = Vector2.Zero;

            //Set the default formation
            curFormation = formationManager.currentFormation;

            //Make the current formation public
            Defines.playersGestures.Add(playerIndex, curFormation.ID);
            //Make the current fusion mode public
            Defines.playerFusionTriggered.Add(playerIndex, formationManager.gestureComponent.fusionGestureMode);
        }
        public void Update(GameTime gameTime, GamePadState currentState)
        {
            UpdateInput(gameTime, currentState);

            //Update the formation manager to check for new formations
            formationManager.Update(gameTime, numActiveShips, fixedPoint);

            //Update our global fusion mode flag
            Defines.playerFusionTriggered[this.currentPlayerIndex] = formationManager.gestureComponent.fusionGestureMode;

            //If the formation manager set a new formation
            if (curFormation.ID != formationManager.currentFormation.ID)
            {
                changedFormations = true;
                //Change our new current formation
                curFormation = formationManager.currentFormation;
                //Update our global formation/gesture
                Defines.playersGestures[this.currentPlayerIndex] = curFormation.ID;
                this.interpTimeSoFar = TimeSpan.Zero;
            }

            this.UpdateShips(gameTime);
        }