public void Update(Player player, GameTime theGameTime, ExplosionHandler explosions, ItemHandler ih, SoundHandler sounds, Camera c) { foreach (Tower t in towers) t.Update(player, theGameTime, explosions, sounds, c); foreach (FlashDoor f in doors) f.Update(theGameTime); foreach (ZombieDispenser z in zombies) z.Update(theGameTime, explosions, ih, c); }
public void Update(GameTime theGameTime, ExplosionHandler explosions, ItemHandler ih, Camera c) { if(random.Next(200) == (int)X / 64) { if (random.Next(2) == 0) newZombie = new Zombie(new Vector2(this.X + 8, this.Y + 48), new Vector2(-1, 1)); else newZombie = new Zombie(new Vector2(this.X + 8, this.Y + 48), new Vector2(1, 1)); newZombie.LoadContent(contentManager); zombies.Add(newZombie); newZombie = null; } foreach (Zombie z in zombies) if (z.Visible) z.Update(theGameTime, c); this.RemoveZombies(explosions, ih); this.Animate(); }
protected override void Initialize() { p = new Player(new Vector2(0, 0)); l = new Level(); l.Initialize(currentLevel, currentLevelType); items = new ItemHandler(this.Content); items.Initialize(currentLevel); enemies = new EnemyHandler(); enemies.Initiliaze(currentLevel); explosions = new ExplosionHandler(); sounds = new SoundHandler(); camera = new Camera(graphics.GraphicsDevice.Viewport); ch = new CollisionHandler(); this.ChangeLevel = false; base.Initialize(); }
private void RemoveZombies(ExplosionHandler explosions, ItemHandler ih) { foreach (Zombie z in zombies) if (z.Y > 550 || !z.Visible) { if (random.Next(10) == 1) ih.AddFirstAid(z.Position, z.DX); else if (random.Next(5) % 2 == 0) ih.AddAcid(z.Position, z.DX); explosions.AddExplosion(new Vector2(z.X + 20 * z.Scale, z.Y + 10 * z.Scale), contentManager, 4, 15, "blood", 32); zombies.Remove(z); break; } }
public void HandleItemCollision(Player p, ItemHandler i, ExplosionHandler explosions, Level l, SoundHandler sounds) { if (p.Jumping || p.Falling) playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(48 * p.Scale)); else { playerRectangle = p.Crouching ? new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 9 * p.Scale), (int)(9 * p.Scale), (int)(50 * p.Scale)) : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale)); } foreach (Coin c in i.coins) if (c.Visible) { coinRectangle = new Rectangle((int)c.X, (int)c.Y, 16, 16); if (coinRectangle.Intersects(playerRectangle)) { sounds.PlayPickUp(); c.Visible = false; p.Score += 5; } } foreach (FirstAid f in i.firstAids) { f.Falling = true; firstAidRectangle = new Rectangle((int)f.X + 1, (int)f.Y + 3, 14, 12); foreach (MacroBlock mb in l.levelBlocks) { if (firstAidRectangle.Intersects(mb.GetRectangle())) f.Falling = false; } if(playerRectangle.Intersects(firstAidRectangle)) { if (p.Hitpoints + firstAidHealth <= 100) p.Hitpoints += firstAidHealth; else p.Hitpoints = 100; f.Visible = false; } } foreach (Acid a in i.acidBalls) { a.Falling = true; acidRectangle = new Rectangle((int)a.X - 6, (int)a.Y - 6, 10, 10); foreach (MacroBlock mb in l.levelBlocks) { if (acidRectangle.Intersects(mb.GetRectangle())) a.Falling = false; } if(playerRectangle.Intersects(acidRectangle) && !a.Exploded) { sounds.PlayHurt(p); p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg) / 2; explosions.AddExplosion(new Vector2(a.Position.X - 8, a.Position.Y - 8), a.contentManager, 9, 27, "acid", 16); a.Exploded = true; } } }