Example #1
0
        /// <summary>
        /// Handle user input to the actions menu.
        /// </summary>
        public void UpdateActionsMenu()
        {
            bool isMenuItemPressed = false;

            if (firstCombatMenuPosition != Rectangle.Empty)
            {
                int x = firstCombatMenuPosition.X;
                for (int playerCount = 0; playerCount < CombatEngine.Players.Count; playerCount++)
                {
                    for (int actionIndex = 0; actionIndex < actionList.Length; actionIndex++)
                    {
                        float yPosition = firstCombatMenuPosition.Y;
                        if (actionIndex + 1 > 1)
                        {
                            yPosition = yPosition + (heightInterval * actionIndex + 1);
                        }
                        Rectangle currentActionPosition = new Rectangle(x, (int)yPosition,
                                                                        (int)(firstCombatMenuPosition.Width * ScaledVector2.ScaleFactor),
                                                                        (int)(firstCombatMenuPosition.Height * ScaledVector2.ScaleFactor));
                        if (InputManager.IsButtonClicked(currentActionPosition))
                        {
                            highlightedAction = actionIndex;
                            isMenuItemPressed = true;
                            break;
                        }
                    }
                    x += (int)(activeCharInfoTexture.Width * ScaledVector2.DrawFactor - 6f * ScaledVector2.ScaleFactor);
                }
            }

            // select an action
            if (isMenuItemPressed)
            {
                switch (actionList[highlightedAction])
                {
                case "Attack":
                {
                    ActionText = "Performing a Melee Attack";
                    CombatEngine.HighlightedCombatant.CombatAction =
                        new MeleeCombatAction(CombatEngine.HighlightedCombatant);
                    CombatEngine.HighlightedCombatant.CombatAction.Target =
                        CombatEngine.FirstEnemyTarget;
                }
                break;

                case "Spell":
                {
                    SpellbookScreen spellbookScreen = new SpellbookScreen(
                        CombatEngine.HighlightedCombatant.Character,
                        CombatEngine.HighlightedCombatant.Statistics);
                    spellbookScreen.SpellSelected +=
                        new SpellbookScreen.SpellSelectedHandler(
                            spellbookScreen_SpellSelected);
                    Session.ScreenManager.AddScreen(spellbookScreen);
                }
                break;

                case "Item":
                {
                    InventoryScreen inventoryScreen = new InventoryScreen(true);
                    inventoryScreen.GearSelected +=
                        new InventoryScreen.GearSelectedHandler(
                            inventoryScreen_GearSelected);
                    Session.ScreenManager.AddScreen(inventoryScreen);
                }
                break;

                case "Defend":
                {
                    ActionText = "Defending";
                    CombatEngine.HighlightedCombatant.CombatAction =
                        new DefendCombatAction(
                            CombatEngine.HighlightedCombatant);
                    CombatEngine.HighlightedCombatant.CombatAction.Start();
                }
                break;

                case "Flee":
                    CombatEngine.AttemptFlee();
                    break;
                }
                return;
            }
        }
Example #2
0
        /// <summary>
        /// Handle user input to the actions menu.
        /// </summary>
        public void UpdateActionsMenu()
        {
            // cursor up
            if (InputManager.IsActionTriggered(InputManager.Action.CursorUp))
            {
                if (highlightedAction > 0)
                {
                    highlightedAction--;
                }
                return;
            }
            // cursor down
            if (InputManager.IsActionTriggered(InputManager.Action.CursorDown))
            {
                if (highlightedAction < actionList.Length - 1)
                {
                    highlightedAction++;
                }
                return;
            }
            // select an action
            if (InputManager.IsActionTriggered(InputManager.Action.Ok))
            {
                switch (actionList[highlightedAction])
                {
                case "Attack":
                {
                    ActionText = "Performing a Melee Attack";
                    CombatEngine.HighlightedCombatant.CombatAction =
                        new MeleeCombatAction(CombatEngine.HighlightedCombatant);
                    CombatEngine.HighlightedCombatant.CombatAction.Target =
                        CombatEngine.FirstEnemyTarget;
                }
                break;

                case "Spell":
                {
                    SpellbookScreen spellbookScreen = new SpellbookScreen(
                        CombatEngine.HighlightedCombatant.Character,
                        CombatEngine.HighlightedCombatant.Statistics);
                    spellbookScreen.SpellSelected +=
                        new SpellbookScreen.SpellSelectedHandler(
                            spellbookScreen_SpellSelected);
                    Session.ScreenManager.AddScreen(spellbookScreen);
                }
                break;

                case "Item":
                {
                    InventoryScreen inventoryScreen = new InventoryScreen(true);
                    inventoryScreen.GearSelected +=
                        new InventoryScreen.GearSelectedHandler(
                            inventoryScreen_GearSelected);
                    Session.ScreenManager.AddScreen(inventoryScreen);
                }
                break;

                case "Defend":
                {
                    ActionText = "Defending";
                    CombatEngine.HighlightedCombatant.CombatAction =
                        new DefendCombatAction(
                            CombatEngine.HighlightedCombatant);
                    CombatEngine.HighlightedCombatant.CombatAction.Start();
                }
                break;

                case "Flee":
                    CombatEngine.AttemptFlee();
                    break;
                }
                return;
            }
        }