Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            inputState.Update();

            if (showingWinScreen != null)
            {
                foreach (UIButton button in winScreenButtons)
                {
                    button.Update(inputState);
                }
                return;
            }
            else if (currentLevel == null)
            {
                levelScreen.Update(inputState);

                foreach (UIButton button in mapScreenButtons)
                {
                    button.Update(inputState);
                }

                if (levelScreen.selectedLevel != null)
                {
                    StartLevel(levelScreen.selectedLevel);
                }
                else
                {
                    return;
                }
            }

            foreach (UIButton button in gameScreenButtons)
            {
                button.Update(inputState);
            }

            // ignore all input while the animation is in progress
            // (TODO: skip button)
            if (!animation.finished)
            {
                animation.Update(gameTime);
                if (animation.finished)
                {
                    gameStates.Add(nextGameState);
                    selectionState = new UISelectionState(nextGameState);
                }
                else
                {
                    return;
                }
            }

            if (gameStates != null)
            {
                if (gameStates.Last().gameEndState == GameState.GameEndState.GameWon)
                {
                    if (inputState.WasMouseLeftJustPressed())
                    {
                        // you won!
                        ReturnToMap(true);
                    }
                }
                else
                {
                    GameState gameState = gameStates.Last();
                    selectionState.ClearPlaying();
                    foreach (CardCatalog catalog in catalogs)
                    {
                        catalog.Update(gameState, selectionState);
                        if (selectionState.TryPlay(this, gameState))
                        {
                            break;
                        }
                    }
                }
            }

            base.Update(gameTime);
        }
Exemplo n.º 2
0
 public void StartLevel(LevelState levelState)
 {
     currentLevel = levelState;
     showingWinScreen = null;
     if (levelState != null)
     {
         gameStates = new List<GameState>();
         GameState newState = new GameState(levelState.script);
         gameStateOnSkip = newState.GetGameStateOnSkip();
         gameStates.Add(newState);
         selectionState = new UISelectionState(newState);
     }
 }
Exemplo n.º 3
0
        public void Draw(SpriteBatch spriteBatch, GameState playState, UISelectionState selectionState)
        {
            int cardListIdx = 0;
            int visibleCardIdx = 0;
            //            int selectSize = 5;

            if (cardList == null)
                return;

            foreach (Card baseCard in cardList)
            {
                if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet))
                {
                    cardListIdx++;
                    continue;
                }

                Card c = GetUpgrade(baseCard);
                bool canUpgrade = CanUpgrade(baseCard);

                CardState state = selectionState.GetCardState(c);

                Rectangle frameRect = new Rectangle(rect.Left, rect.Top + visibleCardIdx * cardHeight, c.frameTexture.Width - (canUpgrade ? 16 : 0), cardHeight);

                c.Draw(spriteBatch, frameRect, state, (selectedCardIdx == cardListIdx));

                if (canUpgrade)
                {
                    Rectangle upgradeRect = new Rectangle(rect.Right-16, rect.Top + visibleCardIdx * cardHeight, 16, cardHeight);
                    bool selectedThisUpgrade = selectedCardUpgrade && (selectedCardIdx == cardListIdx);
                    spriteBatch.Draw(Game1.upgradeTexture, upgradeRect, selectedThisUpgrade? Color.Red: Color.White);
                }

                if (selectedCardIdx == cardListIdx && !selectedCardUpgrade)
                {
                    Card baseSelectedCard = cardList[selectedCardIdx];
                    Card selectedCard = GetUpgrade(baseSelectedCard);
                    TextChanges changes = playState.getTextChanges(baseSelectedCard);

                    Vector2 tooltipPos;
                    Tooltip.Align alignment;
                    if(rect.Left == 0)
                    {
                        tooltipPos = new Vector2(rect.Left + selectedCard.frameTexture.Width, rect.Top + visibleCardIdx * cardHeight);
                        alignment = Tooltip.Align.LEFT;
                    }
                    else
                    {
                        tooltipPos = new Vector2(rect.Left, rect.Top + visibleCardIdx * cardHeight);
                        alignment = Tooltip.Align.RIGHT;
                    }

                    Tooltip.DrawTooltip(spriteBatch, Game1.font, Game1.tooltipBG, changes.Apply(selectedCard.description), tooltipPos, alignment);
                }

                visibleCardIdx++;
                cardListIdx++;
            }
        }
Exemplo n.º 4
0
        public void PlayTurn(Card c, Minion caster, TriggerItem target)
        {
            if (c.effect != null && c.effect is Effect_Rewind)
            {
                if (gameStates.Count <= 1)
                    return;
                // rewind isn't really a spell like everything else
                gameStates.RemoveAt(gameStates.Count - 1);
                gameStateOnSkip = gameStates.Last().GetGameStateOnSkip();
                selectionState = new UISelectionState(gameStates.Last());
            }
            else
            {
                GameState oldGameState = gameStates.Last();
                if (oldGameState.CanPlayCard(c, target))
                {
                    nextGameState = new GameState(gameStates.Last());

                    animation.Clear();
                    if (caster == null)
                        caster = nextGameState.wizard;

                    nextGameState.PlayCard(c, caster, nextGameState.Adapt(target), animation);
                    nextGameState.TurnEffects(animation);

                    gameStateOnSkip = nextGameState.GetGameStateOnSkip();
                }
            }
        }
Exemplo n.º 5
0
        public void Update(GameState playState, UISelectionState selectionState)
        {
            selectedCardUpgrade = false;

            if (cardList == null || !rect.Contains(Game1.inputState.MousePos))
            {
                selectedCardIdx = -1;
            }
            else
            {
                int cardListIdx = 0;
                int cardBottom = rect.Top;

                foreach (Card baseCard in cardList)
                {
                    if (!baseCard.unlocked || !playState.HasSpellSet(baseCard.spellSet))
                    {
                        cardListIdx++;
                        continue;
                    }

                    Card c = GetUpgrade(baseCard);

                    cardBottom += cardHeight;

                    if (Game1.inputState.MousePos.Y < cardBottom)
                    {
                        selectedCardIdx = cardListIdx;
                        if ( Game1.inputState.MousePos.X > rect.Right - 16 && CanUpgrade(baseCard) )
                        {
                            selectedCardUpgrade = true;
                        }
                        break;
                    }
                    cardListIdx++;
                }

                if (Game1.inputState.MousePos.Y > cardBottom)
                {
                    selectedCardIdx = -1;
                }
            }

            if (Game1.inputState.WasMouseLeftJustPressed())
            {
                if (selectedCardIdx != -1)
                {
                    selectionState.ClickedCard(cardList[selectedCardIdx], selectedCardUpgrade);
                }
                else
                {
                    selectionState.ClickedPosition();
                }
            }
        }