public void checkHealth(ContentManager content) { for (int i = 0; i < player.Count; i++) { if (player[i].isAlive() == false) { player[i].kill(content); player.Remove(player[i]); } } for (int i = 0; i < artificial.Count; i++) { if (artificial[i].isAlive() == false) { MoraleBar.resourceAdd(resourceUtil(artificial[i].type)); clink.Play(); artificial.Remove(artificial[i]); } } }
// Change map and set managers to be equal to the current map /// <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) { //if (riverDefenseSelector.getOccupied()) // betaInitialization(); ClickTimer += gameTime.ElapsedGameTime.TotalMilliseconds; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } mouseCurrent = Mouse.GetState(); KeyboardState keyboardState = Keyboard.GetState(); healthChecker.Update(ModelManager.player, ModelManager.artificial); healthChecker.checkHealth(this.Content); ModelManager.player = healthChecker.player; ModelManager.artificial = healthChecker.artificial; attackChecker.Update(ref ModelManager.player, ref ModelManager.artificial); attackChecker.autoAttacks(); projMan.fireProjectiles(); if (built) { mBar.calculateScore(); } //inputManager.Update(mouseCurrent, mousePrev, keyboardState, ref towers, ref gameobj); if (!built && playable) // Enter build phase if built is False, notice true flag at the end indicating we're in build phase { //Console.WriteLine("a"); // Why is the "buildPhase" Boolean always true? Should it be equal to "built"? // 2 checks: either you don’t want to use all your resources, and want to start the game now, or you’ve used all your resources // and the player should receive a “ready check” if (keyboardState.IsKeyDown(Keys.Enter)) { // once we deplete our build resources, set built to true (doing so will initialize enemy AI units and starts the level) built = true; MoraleBar.resourceAdd(playerResources); } inputManager.Update(mouseCurrent, mousePrev, ref ClickTimer, keyboardState, ref groupedUnits, ref ModelManager.player, ref ModelManager.artificial, ref loadMan, ref projMan, this.Content, ref MoraleBar.resources, true); //MoraleBar.resourceVal(buildResources); } else if (built && initialized)// player is not building in build phase but rather building reinforcements - notice the false flag at the end indicating not build phase { //Console.WriteLine("b"); inputManager.Update(mouseCurrent, mousePrev, ref ClickTimer, keyboardState, ref groupedUnits, ref ModelManager.player, ref ModelManager.artificial, ref loadMan, ref projMan, Content, ref MoraleBar.resources, false); //MoraleBar.resourceVal(playerResources); } else { int noResources = 0; inputManager.Update(mouseCurrent, mousePrev, ref ClickTimer, keyboardState, ref groupedUnits, ref ModelManager.player, ref ModelManager.artificial, ref loadMan, ref projMan, Content, ref noResources, false); } if (built && !initialized)// && castleDefenseSelector.getOccupied() == true) { //Console.WriteLine("c"); if (screenManager.currentMap.name.Equals("Content/castleDefense.txt")) { castleDefenseSpawn(); } else if (screenManager.currentMap.name.Equals("Content/castleSiege.txt")) { castleSiegeSpawn(); } else if (screenManager.currentMap.name.Equals("Content/riverDefense.txt")) { riverDefenseSpawn(); } initialized = true; // set initialized to true to prevent looped enemy unit spawning } if (initialized) { //Console.WriteLine("d"); theResource.ssY = playerResources * 32; } loadMan.load(Content, ModelManager.artificial); loadMan.load(Content, ModelManager.player); movementManager.moveObjects(ModelManager.player, ModelManager.artificial); aiManager.SetAIDestinations2(ModelManager.artificial); if ((ModelManager.player.Count == 0) && built) { screenManager.victory = "defeat"; SoundEffect defeatEffect = Content.Load <SoundEffect>("wilhelm.wav"); defeatEffect.Play(); ModelManager.artificial.Clear(); testCommander(); mBar.waveNum = 0; loadMan.load(Content, ModelManager.player); built = false; playable = false; initialized = false; if (screenManager.currentMap.name.Equals("Content/castleDefense.txt")) { prevResources = 10; buildResources = 0; MoraleBar.resourceVal(buildResources); currentTransition = "defeatScreen"; completeTransition = false; } else if (screenManager.currentMap.name.Equals("Content/riverDefense.txt")) { prevResources = 10; buildResources = 0; MoraleBar.resourceVal(buildResources); currentTransition = "fallBackToTheCastle"; completeTransition = false; } else if (screenManager.currentMap.name.Equals("Content/castleSiege.txt")) { playerResources = 10; prevResources = 15; buildResources = 0; MoraleBar.resourceVal(buildResources); currentTransition = "fallBackToTheRiver"; completeTransition = false; } testBeta = true; //Console.WriteLine("interaction for defeatscreenselector: " + screenManager.allSelectors[0].getInteraction()); } else if ((ModelManager.artificial.Count == 0) && built) { screenManager.victory = "victory"; ModelManager.player.Clear(); testCommander(); mBar.waveNum = 0; loadMan.load(Content, ModelManager.player); built = false; playable = false; initialized = false; if (screenManager.currentMap.name.Equals("Content/castleDefense.txt")) { if (MoraleBar.resources > 15) { prevResources = MoraleBar.resources; } else { prevResources = 15; } currentTransition = "onwardToTheRiver"; playerResources = 10; buildResources = 0; MoraleBar.resourceVal(buildResources); completeTransition = false; } else if (screenManager.currentMap.name.Equals("Content/riverDefense.txt")) { if (MoraleBar.resources > 20) { prevResources = MoraleBar.resources; } else { prevResources = 20; } playerResources = 10; buildResources = 0; MoraleBar.resourceVal(buildResources); currentTransition = "onwardToTheCastle"; completeTransition = false; } else if (screenManager.currentMap.name.Equals("Content/castleSiege.txt")) { playerResources = 10; prevResources = 10; buildResources = 0; MoraleBar.resourceVal(buildResources); currentTransition = "victoryScreen"; completeTransition = false; } testBeta = true; } if (completeTransition == false && keyboardState.IsKeyDown(Keys.Enter)) { completeTransition = true; currentTransition = "null"; } screenManager.updateSelectors(screenManager.victory); if (screenManager.currentMap.name.Equals("Content/MainScreen.txt") && completeTransition == true && whatIsTruth == false) { currentTransition = "levelSelect"; whatIsTruth = true; } /*if (screenManager.victory.Equals("victory") && screenManager.currentMap.name.Equals("castleSiege")) * { * screenManager.victory = "undef"; * screenManager.prevMap = screenManager.allMaps[screenManager.progressIndex]; * screenManager.progressIndex++; * screenManager.currentMap = screenManager.allMaps[screenManager.progressIndex]; * screenManager.nextMap = screenManager.allMaps[screenManager.progressIndex + 1]; * * }*/ //aiManager.SetAIDestinations(modMan.artificial); // TyDigit: Change the digit based on amount of resources left mousePrev = mouseCurrent; base.Update(gameTime); }