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(); }
public void HandleZombiesMovingCollision(EnemyHandler e, Level l) { foreach (ZombieDispenser zd in e.zombies) foreach (Zombie z in zd.zombies) { z.Falling = true; zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 60 * z.Scale), (int)(28 * z.Scale), (int)(6 * z.Scale)); foreach (MacroBlock mb in l.levelBlocks) if (zombieRectangle.Intersects(mb.GetRectangle())) { z.Falling = false; 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; } } }
public void HandleMovingCollision(Player p, Level l, Camera c) { p.Falling = true; playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 58 * p.Scale), (int)(16 * p.Scale), (int)(6 * p.Scale)); foreach (MacroBlock mb in l.levelBlocks) if (mb.IsOnScreen(c)) { if (playerRectangle.Intersects(mb.GetRectangle())) { p.Falling = false; break; } } }
public void HandleEndLevel(Game1 game, Player p, Level l) { playerRectangle = new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale)); eolRectangle = new Rectangle((int)(l.endOflevel.X + 42), (int)l.endOflevel.Y, 10, 64); if (playerRectangle.Intersects(eolRectangle)) game.ChangeLevel = true; }