public static LeaveMeAlone.GameState Update(GameTime gameTime)
        {
            lastMouseState    = currentMouseState;
            currentMouseState = Mouse.GetState();
            if (menu_state == MenuState.main)
            {
                if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                {
                    if (newGame.Intersects(currentMouseState.X, currentMouseState.Y))
                    {
                        menu_state = MenuState.opening;
                    }
                    else if (loadGame.Intersects(currentMouseState.X, currentMouseState.Y) && !isNewGame)
                    {
                        LeaveMeAlone.Main_Song_Instance.Stop();
                        LeaveMeAlone.Menu_Song_Instance.Play();
                        return(LeaveMeAlone.GameState.Upgrade);
                    }
                    else if (quit.Intersects(currentMouseState.X, currentMouseState.Y))
                    {
                        return(LeaveMeAlone.GameState.Quit);
                    }
                }
            }
            else if (menu_state == MenuState.opening)
            {
                if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
                {
                    if (next_intro.Intersects(currentMouseState.X, currentMouseState.Y))
                    {
                        line_number++;
                        opening_timer = 0;
                    }
                    if (skip_intro.Intersects(currentMouseState.X, currentMouseState.Y))
                    {
                        line_number = 1 + opening_monologue.Count();
                    }
                }
                if (line_number == 1 + opening_monologue.Count())
                {
                    menu_state = MenuState.boss;
                }
                else if (opening_timer > 300)
                {
                    if (line_number != opening_monologue.Count())
                    {
                        opening_timer = 0;
                    }
                    line_number++;
                }
                else
                {
                    opening_timer++;
                }
            }
            else
            {
                if (brute.Contains(new Vector2(currentMouseState.X, currentMouseState.Y)))
                {
                    bruteHover      = true;
                    mastermindHover = false;
                    operativeHover  = false;
                    brute.walk();
                    mastermind.idle();
                    operative.idle();
                    current = brute;
                }
                else if (mastermind.Contains(new Vector2(currentMouseState.X, currentMouseState.Y)))
                {
                    bruteHover      = false;
                    mastermindHover = true;
                    operativeHover  = false;
                    brute.idle();
                    mastermind.walk();
                    operative.idle();
                    current = mastermind;
                }
                else if (operative.Contains(new Vector2(currentMouseState.X, currentMouseState.Y)))
                {
                    bruteHover      = false;
                    mastermindHover = false;
                    operativeHover  = true;
                    brute.idle();
                    mastermind.idle();
                    operative.walk();
                    current = operative;
                }
                else
                {
                    current         = null;
                    bruteHover      = false;
                    mastermindHover = false;
                    operativeHover  = false;
                    brute.idle();
                    mastermind.idle();
                    operative.idle();
                }
                brute.Update(gameTime);
                mastermind.Update(gameTime);
                operative.Update(gameTime);
                if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released && canFinish)
                {
                    Vector2 mousePos = new Vector2(currentMouseState.X, currentMouseState.Y);
                    if (operative.Contains(mousePos) || brute.Contains(mousePos) || mastermind.Contains(mousePos))
                    {
                        BattleManager.boss = new Character(current.bossType, 1, new Vector2(BattleManager.bossLoc.X, BattleManager.bossLoc.Y));


                        BattleManager.heroes = PartyManager.CreateParty();

                        LeaveMeAlone.Main_Song_Instance.Stop();

                        UpgradeMenu.boughtRooms.Clear();
                        Resources.gold = 1000;
                        Resources.exp  = 0;
                        UpgradeMenu.Init(current);
                        LairManager.Init();
                        PartyManager.Init();
                        LairManager.EndOfGame   = false;
                        LairManager.TowerLevel  = 0;
                        LairManager.MaxLevel    = 3;
                        LairManager.LairRooms   = new List <Room>();
                        LairManager.boughtRooms = new List <UpgradeMenu.ButtonRoom>();

                        //return LeaveMeAlone.GameState.Upgrade;
                        return(LeaveMeAlone.GameState.Upgrade);
                    }
                }
                canFinish = true;
            }
            return(LeaveMeAlone.GameState.Main);
        }
Exemple #2
0
        public static LeaveMeAlone.GameState Update(GameTime g)
        {
            lastMouseState    = currentMouseState;
            currentMouseState = Mouse.GetState();
            int xpos = currentMouseState.X;
            int ypos = currentMouseState.Y;

            texts["gold"].changeMessage("Gold: " + Resources.gold);
            texts["level"].changeMessage("Level: " + BattleManager.boss.level);

            if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                left_click = false;
            }
            if (Mouse.GetState().RightButton == ButtonState.Released)
            {
                right_click = false;
            }

            if (BattleManager.boss.level < 2)
            {
                HandleTutorial();
            }

            foreach (Skill s in BattleManager.boss.skills)
            {
                skilltree.SkillButtons[s].text.color = Color.Black;
            }
            //gets things that haven't been bought and colors them
            foreach (Skill s in skilltree.SkillButtons.Keys.Except(BattleManager.boss.skills))
            {
                if (s.cost > Resources.gold || BattleManager.boss.level < s.level)
                {
                    skilltree.SkillButtons[s].text.color = Color.Red;
                }
                else
                {
                    skilltree.SkillButtons[s].text.color = Color.Blue;
                }
            }

            bool hovered = false;

            foreach (Skill s in skilltree.SkillButtons.Keys)
            {
                if (skilltree.SkillButtons[s].Intersects(currentMouseState.X, currentMouseState.Y))
                {
                    hovertext.changeMessage(s.name + ":\n" + s.description);
                    hovered = true;
                }
            }
            //Hover over Stats button
            if (statsTitleRect.Contains(currentMouseState.X, currentMouseState.Y))
            {
                statsText.changeMessage(BattleManager.boss.StatsToString());
                Vector2 statmeasurements = statsText.getMeasurements(300);
                statsText.position = new Vector2(statsTitle.position.X, statsTitleRect.Y + statsTitleRect.Height + 10);
                Console.WriteLine("statspos" + statsText.position.ToString());
                statsTextRect = new Rectangle((int)statsText.position.X - 10, (int)statsText.position.Y - 10, 300, (int)statmeasurements.Y + 10);
            }
            else
            {
                statsText.changeMessage("");
            }

            //perfect place for polymophism Chris
            hovered = false;
            foreach (Skill s in skilltree.SkillButtons.Keys)
            {
                if (skilltree.SkillButtons[s].Intersects(currentMouseState.X, currentMouseState.Y))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(s.name + ":");
                    if (BattleManager.boss.skills.Contains(s))
                    {
                        sb.Append(" (bought)");
                    }
                    else
                    {
                        sb.Append(" (Cost: " + s.cost + ")");
                    }
                    sb.Append("\nMana Cost: " + s.energy + "\nCooldown: " + s.cooldown + "\n");
                    sb.Append("\n" + s.description);
                    hovertext.changeMessage(sb.ToString());
                    hovered = true;
                }
            }
            foreach (ButtonRoom r in AvailableRooms)
            {
                if (r.b.Intersects(currentMouseState.X, currentMouseState.Y))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(r.r.name + ":");
                    if (boughtRooms.Contains(r.r))
                    {
                        sb.Append(" (bought)");
                    }
                    else
                    {
                        sb.Append(" (Cost: " + r.r.cost + ")");
                    }
                    sb.Append("\n" + r.r.description);
                    hovertext.changeMessage(sb.ToString());
                    hovered = true;
                }
            }
            if (hovered == false)
            {
                hovertext.changeMessage("");
            }
            selectedBoss.Update(g);
            //if (lastMouseState.LeftButton == ButtonState.Pressed && currentMouseState.LeftButton == ButtonState.Released)
            if (leftClicked())
            {
                //check if a room was clicked on
                for (int x = 0; x < AvailableRooms.Length; x++)
                {
                    if (BattleManager.boss.selected_rooms.Contains(AvailableRooms[x].r) == false && AvailableRooms[x].b.Intersects(currentMouseState.X, currentMouseState.Y) && AvailableRooms[x].r.level != -1)
                    {
                        if (AvailableRooms[x].r.cost < Resources.gold)
                        {
                            BattleManager.boss.selected_rooms.Add(AvailableRooms[x].r);
                            LairManager.addRoom(AvailableRooms[x]);
                            boughtRooms.Add(AvailableRooms[x].r);
                            Resources.gold -= AvailableRooms[x].r.cost;
                            tutorial_state  = TutorialState.Back;
                            buyingSound.Play();
                        }
                    }
                }
                //check the next button
                if (next.Intersects(currentMouseState.X, currentMouseState.Y))
                {
                    BattleManager.bossDefaultPosition();
                    LairManager.tutorial_state = LairManager.TutorialState.Build1;
                    return(LeaveMeAlone.GameState.Lair);
                }
                //check if we clicked on a skill
                foreach (Skill s in skilltree.SkillButtons.Keys)
                {
                    if (skilltree.SkillButtons[s].Intersects(currentMouseState.X, currentMouseState.Y))
                    {
                        Console.WriteLine("Got one!");
                        if (BattleManager.boss.skills.Contains(s) == false && BattleManager.boss.level >= s.level)
                        {
                            //if you have enough money, buy it
                            if (s.cost < Resources.gold)
                            {
                                BattleManager.boss.addSkill(s);
                                buyingSound.Play();
                                tutorial_state  = TutorialState.BuyRoom;
                                Resources.gold -= s.cost;
                                if (s == SkillTree.final_skill[BattleManager.boss.charType])
                                {
                                    LairManager.EndOfGame = true;
                                    LairManager.nextwaveBtn.rectangle.X = LeaveMeAlone.BackgroundRect.X;
                                    LairManager.nextwaveBtn.rectangle.Y = LeaveMeAlone.BackgroundRect.Height - 200;
                                }
                                //Console.WriteLine(BattleManager.boss.skills.Count);
                            }
                        }
                        else
                        {
                            //When a skill isn't selected to swap, it should be set to default(Skill)
                            if (selectedSkillSwapButton.s != default(Skill) && BattleManager.boss.skills.Contains(s) == true && BattleManager.boss.selected_skills.Contains(s) == false)
                            {
                                int index = BattleManager.boss.selected_skills.IndexOf(selectedSkillSwapButton.s);
                                BattleManager.boss.selected_skills[index] = s;
                                swappingSound.Play();
                                Console.WriteLine("swapped");
                            }
                        }
                        //Console.WriteLine(s+" pressed");
                    }
                }
                updateSelectedSkills();
                bool flag = false;
                for (int x = 0; x < SelectedSkills.Length; x++)
                {
                    var buttonStuff = SelectedSkills[x];

                    if (buttonStuff.b.Intersects(currentMouseState.X, currentMouseState.Y) && buttonStuff.s != null)
                    {
                        //already have a selected thing;
                        if (selectedSkillSwapButton.b != null)
                        {
                            selectedSkillSwapButton.b.selected = false;
                        }
                        flag = true;
                        selectedSkillSwapButton            = buttonStuff;
                        selectedSkillSwapButton.b.selected = true;
                        //Console.WriteLine("selected " + buttonStuff.s.name);
                    }
                }
                if (flag == false)
                {
                    if (selectedSkillSwapButton.b != null)
                    {
                        selectedSkillSwapButton.b.selected = false;
                    }
                    selectedSkillSwapButton = new ButtonSkill();;
                }
            }

            measurements = hovertext.getMeasurements(hovertextRect.Width - 15);
            if (xpos + hovertextRect.Width > LeaveMeAlone.WindowX - 20)
            {
                hovertextRect.X = LeaveMeAlone.WindowX - hovertextRect.Width - 20;
            }
            else
            {
                hovertextRect.X = currentMouseState.X + 10;
            }
            if (ypos + measurements.Y > LeaveMeAlone.WindowY - 20)
            {
                hovertextRect.Y = LeaveMeAlone.WindowY - (int)measurements.Y - 20;
            }
            else
            {
                hovertextRect.Y = currentMouseState.Y + 10;
            }
            return(LeaveMeAlone.GameState.Upgrade);
        }