/// <summary> /// Override Logic method /// </summary> public override void Logic() { //Set the target to the first entry in the survivor list Target = World.AliveSurvivorList.ElementAt(0); //Go through every survivor foreach (Survivor surv in World.AliveSurvivorList) { //If the target has more kills than the next survivor if (Target.Kills >= surv.Kills && surv.IsAlive) { //Set that survivor as the target Target = surv; } } //One in three chance of this happening if (ExtensionMethods.RandomNumber(1, 3) == 2) { //If the Director has enough resources if (World.Director.Resources > SpeedEffect.Instance.Cost) { //Go through all the zombies foreach (Zombie zom in World.ZombieList) { if (CollisionEngine.IsNear(Target, zom)) { //Use either the slow or speed up if (ExtensionMethods.RandomNumber(1, 2) == 2) { //Slow the players SpeedEffect.Instance.Activate(); } else { //Make the zombies go faster SlowEffect.Instance.Activate(); } } } } } //One in three chance of spawning a juggernaught if (ExtensionMethods.RandomNumber(1, 3) == 2) { //Try and spawn a juggernaught WorldDirector.ZombieSpawner("j"); } //One in two chance of spawning an exploder if (ExtensionMethods.RandomNumber(1, 5) == 3) { //Try and spawn a juggernaught WorldDirector.ZombieSpawner("e"); } //One in three chance of spawning a speeder //One in three chance of spawning a juggernaught if (ExtensionMethods.RandomNumber(1, 1000) == 2) { //Try and spawn a juggernaught WorldDirector.ZombieSpawner("s"); } }
//Frames elapsed public static void Update(GameEngine instance) { //Is updating equals true IsUpdating = true; //Update the world director WorldDirector.Update(); //Check for collisions CollisionEngine.collisionHandler(ZombieList, BulletList, SurvivorList, WeaponList); //Call update for every entity in the game foreach (GameEntity entity in GameEntities) { //Update every entity in the game entity.Update(); } //Once every entity has been updated, set the updating flag to false IsUpdating = false; //Add all the newly added entities into the list of added entities foreach (GameEntity entity in AddedEntities) { AddEntityToLists(entity); } //Clear the added entities list AddedEntities.Clear(); //Remove any dead entities //Lambada alogirthims adapted from Michael Hoffmans //http://gamedevelopment.tutsplus.com/tutorials/make-a-neon-vector-shooter-in-xna-more-gameplay--gamedev-10103 GameEntities = GameEntities.Where(x => x.IsAlive).ToList(); ZombieList = ZombieList.Where(x => x.IsAlive).ToList(); BulletList = BulletList.Where(x => x.IsAlive).ToList(); WeaponList = WeaponList.Where(x => x.IsAlive).ToList(); AliveSurvivorList = SurvivorList.Where(x => x.IsAlive).ToList(); //Gameover is true bool gameover = true; //If any survivors are still alive foreach (Survivor surv in SurvivorList) { if (surv.IsAlive == true) { //Then it's not game over gameover = false; } } //If the games over, set the gamestate to gameover if (gameover) { instance.currentState = GameEngine.GameState.GameOver; } }