Beispiel #1
0
        public static void Update(GameTime gameTime)
        {
            MouseController.Update();
            if (gameStarted)
            {
                if (heroPos == null)
                {
                    heroPos = currentLevel.CharacterEntities.FindPosition(hero);
                }

                for (int i = 0; i < xpList.Count; i++)
                {
                    if (xpList[i].update())
                    {
                        xpList.RemoveAt(i);
                        drawXP++;
                    }
                }
                for (int i = 0; i < vattacks.Count; i++)
                {
                    if (vattacks[i].update())
                    {
                        vattacks.RemoveAt(i);
                    }
                }

                for (int i = 0; i < splashes.Count(); i++)
                {
                    if (splashes[i].update())
                    {
                        splashes.RemoveAt(i);
                    }
                }

                if (!GameCommands())
                {
                    currentLevel.testUpdate();
                    //Game turns

                    //hero.TakeTurn(currentLevel);
                    if (charIndex >= currentLevel.CharacterEntities.Entities().Count<GameCharacter>())
                    {
                        charIndex = 0;
                    }
                    while (currentLevel.CharacterEntities.Entities().ElementAt<GameCharacter>(charIndex) != hero)
                    {
                        if (hero != null)
                        {
                            heroPos = currentLevel.CharacterEntities.FindPosition(hero);
                        }
                        if (charIndex < currentLevel.CharacterEntities.Entities().Count<GameCharacter>() && heroPos != null)
                        {
                            IntVec enemyPosition = currentLevel.CharacterEntities.FindPosition(currentLevel.CharacterEntities.Entities().ElementAt<GameCharacter>(charIndex));
                            if (enemyPosition.X > heroPos.X - AIDist &&
                                enemyPosition.X < heroPos.X + AIDist &&
                                enemyPosition.Y > heroPos.Y - AIDist &&
                                enemyPosition.Y < heroPos.Y + AIDist &&
                                HeroClasses.Hero.visible)
                            {
                                if (currentLevel.CharacterEntities.Entities().ElementAt<GameCharacter>(charIndex).TakeTurn(currentLevel))
                                {
                                    currentLevel.InvalidateCache();
                                    charIndex++;

                                }
                            }
                            else
                            {
                                charIndex++;
                            }
                        }
                        if (charIndex >= currentLevel.CharacterEntities.Entities().Count<GameCharacter>())
                        {
                            charIndex = 0;
                        }
                    }

                    charIndex += hero.TakeTurn(currentLevel) ? 1 : 0;

                    if (hero.hasReachedBranchLevel())
                    {
                        tempPosition = currentLevel.CharacterEntities.FindPosition(hero);
                        tempEquip = hero.GetEquipment();
                        tempInventory = hero.GetInventory();
                        currentLevel.CharacterEntities.Remove(hero);

                        if (HeroClasses.Hero.level < 20)
                        {

                            gameStarted = false;
                            showCharSelection = true;

                            if (HeroClasses.Hero.heroRole == Enums.Classes.Warrior)
                            {
                                selection = new CharButton[] { bralwerButton, sentinelButton };
                            }
                            else if (HeroClasses.Hero.heroRole == Enums.Classes.Mage)
                            {
                                selection = new CharButton[] { sorcererButton, magusButton };
                            }
                            else if (HeroClasses.Hero.heroRole == Enums.Classes.Rogue)
                            {
                                selection = new CharButton[] { duelistButton, rangerButton };
                            }
                        }
                        else
                        {
                            //new class, not branching...
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Duelist)
                            {
                                hero = new HeroClasses.Assassin();
                                UpdateAbilities();
                                Log("You are now an Assasin.");
                                splashes.Add(new Splash(upAssassin, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Brawler)
                            {
                                hero = new HeroClasses.Berserker();
                                UpdateAbilities();
                                Log("You are now a Berserker.");
                                splashes.Add(new Splash(upBerserker, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Sentinel)
                            {
                                hero = new HeroClasses.Juggernaut();
                                UpdateAbilities();
                                Log("You are now a Juggernaut.");
                                splashes.Add(new Splash(upJuggernaut, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Sorcerer)
                            {
                                hero = new HeroClasses.Spellweaver();
                                UpdateAbilities();
                                Log("You are now a SpellWeaver.");
                                splashes.Add(new Splash(upSpellweaver, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Magus)
                            {
                                hero = new HeroClasses.SpellBlade();
                                UpdateAbilities();
                                Log("You are now a SpellBlade.");
                                splashes.Add(new Splash(upSpellblade, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                            if (HeroClasses.Hero.heroRole == Enums.Classes.Ranger)
                            {
                                hero = new HeroClasses.Marksman();
                                UpdateAbilities();
                                Log("You are now a Marksman.");
                                splashes.Add(new Splash(upMarksman, new Vector2(game.Width / 2, game.Height / 2), 3, .05f));
                                drawXP = hero.getExperience();
                                gameStarted = true;
                                hero.ObtainItems(tempInventory, tempEquip);
                                hero.obtainStartingGear(currentLevel);
                                currentLevel.CharacterEntities.Add(hero, tempPosition);
                            }
                        }

                    }

                    if (currentLevel.CharacterEntities.FindPosition(hero) != null)
                    {
                        cameraPosition = currentLevel.CharacterEntities.FindPosition(hero);

                        modifiedCameraPosition.X = cameraPosition.X - (windowSizeInTiles.X / 2);
                        modifiedCameraPosition.Y = cameraPosition.Y - (windowSizeInTiles.Y / 2);
                        currentLevel.InvalidateCache();
                    }
                }
            }
            else
            {
                if (mainMenuOpen)
                {
                    if (mageButton.isClicked())
                    {
                        hero = new HeroClasses.Mage();
                        HeroClasses.Hero.level = 5;
                        UpdateAbilities();
                        mainMenuOpen = false;
                        showSaveSlotSelection = true;
                    }
                    if (warriorButton.isClicked())
                    {
                        hero = new HeroClasses.Warrior();
                        HeroClasses.Hero.level = 5;
                        UpdateAbilities();
                        mainMenuOpen = false;
                        showSaveSlotSelection = true;
                    }
                    if (rogueButton.isClicked())
                    {
                        hero = new HeroClasses.Rogue();
                        HeroClasses.Hero.level = 5;
                        UpdateAbilities();
                        mainMenuOpen = false;
                        showSaveSlotSelection = true;
                    }
                    int saveSlot = saveSlotClicked();
                    if (saveSlot != -1)
                    {
                        LoadFromSlot(saveSlot);
                    }
                    if (quitButton.isClicked())
                    {
                        System.Environment.Exit(0);
                    }
                }

                else if (savePromptOpen)
                {
                    if (saveButton.isClicked())
                    {
                        SaveToSlot(currentSaveSlot);
                        System.Environment.Exit(0);
                    }
                    if (continueButton.isClicked())
                    {
                        savePromptOpen = false;
                        gameStarted = true;
                    }
                }
                else if (showSaveSlotSelection)
                {
                    int saveClicked = saveSlotClicked();
                    if (saveClicked != -1)
                    {
                        currentSaveSlot = saveClicked;
                        showSaveSlotSelection = false;
                        StartGame();
                    }

                }
                else if (showEscMenu)
                {
                    if (escQuit.isClicked())
                    {
                        Environment.Exit(0);
                    }
                    if (escContinue.isClicked())
                    {
                        showEscMenu = false;
                        gameStarted = true;
                    }
                    if (escMainMenu.isClicked())
                    {
                        showEscMenu = false;
                        xpList.Clear();
                        currentDungeonLevel = 0;
                        LoadSaveSlots();
                        vattacks.Clear();
                        mainMenuOpen = true;
                    }
                }

                else if (showCharSelection)
                {
                    if (selection.Contains(bralwerButton) && bralwerButton.isClicked())
                    {
                        hero = new HeroClasses.Brawler();
                        UpdateAbilities();
                        Log("You are now a brawler.");
                        showCharSelection = false;
                        gameStarted = true;
                        drawXP = hero.getExperience();
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                    if (selection.Contains(duelistButton) && duelistButton.isClicked())
                    {
                        hero = new HeroClasses.Duelist();
                        UpdateAbilities();
                        Log("You are now a duelist.");
                        showCharSelection = false;
                        drawXP = hero.getExperience();
                        gameStarted = true;
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                    if (selection.Contains(sorcererButton) && sorcererButton.isClicked())
                    {
                        hero = new HeroClasses.Sorcerer();
                        UpdateAbilities();
                        Log("You are now a Sorcerer.");
                        showCharSelection = false;
                        drawXP = hero.getExperience();
                        gameStarted = true;
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                    if (selection.Contains(magusButton) && magusButton.isClicked())
                    {
                        hero = new HeroClasses.Magus();
                        UpdateAbilities();
                        Log("You are now a Magus.");
                        showCharSelection = false;
                        gameStarted = true;
                        drawXP = hero.getExperience();
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                    if (selection.Contains(sentinelButton) && sentinelButton.isClicked())
                    {
                        hero = new HeroClasses.Sentinel();
                        UpdateAbilities();
                        Log("You are now a Sentinel.");
                        showCharSelection = false;
                        gameStarted = true;
                        drawXP = hero.getExperience();
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                    if (selection.Contains(rangerButton) && rangerButton.isClicked())
                    {
                        hero = new HeroClasses.Ranger();
                        UpdateAbilities();
                        Log("You are now a Ranger.");
                        showCharSelection = false;
                        drawXP = hero.getExperience();
                        gameStarted = true;
                        hero.ObtainItems(tempInventory, tempEquip);
                        hero.obtainStartingGear(currentLevel);
                        currentLevel.CharacterEntities.Add(hero, tempPosition);
                    }
                }

                else if (showDeathScreen)
                {
                    if (quitDeathButton.isClicked())
                    {
                        Environment.Exit(0);
                    }
                    if (restartButton.isClicked())
                    {
                        showDeathScreen = false;
                        xpList.Clear();
                        currentDungeonLevel = 0;
                        LoadSaveSlots();
                        vattacks.Clear();
                        mainMenuOpen = true;
                    }
                }

            }

            if (gameStarted)
            {
                Audio.update();
            }

            if (hero != null && !hero.isAlive() && gameStarted)
            {
                gameStarted = false;
                showDeathScreen = true;
            }
        }