protected override void Update(GameTime gameTime) { MouseState lastMs = ms; ms = Mouse.GetState(); KeyboardState keyboard = Keyboard.GetState(); if (currentScreen == ScreenState.Game) { #region Game Logic timer += gameTime.ElapsedGameTime; if (timer > TimeSpan.FromMilliseconds(zombiespawntime)) { timer = TimeSpan.Zero; } zombieSpawn += gameTime.ElapsedGameTime; } List <int> Counter = new List <int>(); for (int i = 0; i < zombies.Count; i++) { for (int j = 0; j < player.Bullets.Count; j++) { if (CheckFloat(player.Bullets[j].Pos.X, zombies[i].Pos.X)) { if (player.Bullets[j].getHitbox().Intersects(zombies[i].ZombieHitbox())) { Counter.Add(i); player.Bullets.RemoveAt(j); j--; killCount++; points += 50; } } } } for (int i = 0; i < Counter.Count; i++) { zombies.RemoveAt(Counter[i]); } if (zombieSpawn > TimeSpan.FromMilliseconds(500)) { zombieSpawn = TimeSpan.Zero; int zombieX; int zombieY; do { zombieX = rand.Next(-500, GraphicsDevice.Viewport.Width + 500); zombieY = rand.Next(-500, GraphicsDevice.Viewport.Height + 500); } while (GraphicsDevice.Viewport.Bounds.Contains(zombieX, zombieY)); zombies.Add(new Zombie((Zombie.ZombieState)rand.Next(0, 3), new Vector2(zombieX, zombieY), Content.Load <Texture2D>("Characters"), Color.White, new Vector2(1, 1), 0f)); } whichZombie = random.Next(0, 3); //move this foreach inside the zombie class foreach (Zombie zombie in zombies) { Vector2 diff2 = player.Pos - zombie.Pos; double rot2 = Math.Atan2(diff2.Y, diff2.X); zombie.Rotation = (float)rot2; Vector2 diff3 = player.Pos - zombie.Pos; diff3.Normalize(); zombie.Pos += diff3 * new Vector2(.05f, .05f) * (float)gameTime.ElapsedGameTime.TotalMilliseconds; bool isHit = false; foreach (Zombie z in zombies) { if (z.ZombieHitbox().Intersects(player.PlayerHitbox())) { isHit = true; break; } } if (isHit) { currentScreen = ScreenState.End; } } #endregion Game Logic player.Update(gameTime, keyboard, ms, lastMs, target, GraphicsDevice.Viewport); if (currentScreen == ScreenState.Start) { //TODO: add logic for start screen. } if (currentScreen == ScreenState.End) { } base.Update(gameTime); }