Example #1
0
 public void HandleBulletTurretCollision(Player p, EnemyHandler e, ExplosionHandler eh)
 {
     foreach(Bullet b in p.bullets)
     {
         bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
         foreach(Tower t in e.towers)
             if(bulletRectangle.Intersects(t.GetRectangle()))
             {
                 b.Visible = false;
                 eh.AddExplosion(b.Position, t.contentManager, 5, 15, "explosion", 32, 0.33f);
             }
     }
 }
Example #2
0
 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;
         }
 }
Example #3
0
        public void HandleZombiePlayerCollision(Player p, EnemyHandler e, ExplosionHandler explosions, SoundHandler sounds)
        {
            playerRectangle = p.Crouching ? new Rectangle((int)(p.X + 24 * p.Scale), (int)(p.Y + 9 * p.Scale), (int)(9 * p.Scale), (int)(40 * p.Scale))
                                          : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));

            foreach (ZombieDispenser zd in e.zombies)
                foreach (Zombie z in zd.zombies)
                    if (z.OnScreen)
                    {
                        zombieRectangle = new Rectangle((int)(z.X + 24 * z.Scale), (int)(z.Y + 9 * z.Scale), (int)(16 * z.Scale), (int)(56 * z.Scale));
                        if (playerRectangle.Intersects(zombieRectangle))
                        {
                            z.Collide = true;
                            if (z.CanBite)
                            {
                                if (z.DX < 0 && p.DX >= 0)
                                {
                                    explosions.AddExplosion(new Vector2(p.X - 9 * p.Scale, p.Y), p.contentManager, 4, 15, "blood", 32);
                                    p.DX = -4f;
                                    p.Push = true;
                                    p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg);
                                    sounds.PlayHurt(p, z);
                                    z.realoadTime = 0.0f;
                                }
                                else if (z.DX > 0 && p.DX <= 0)
                                {
                                    explosions.AddExplosion(new Vector2(p.X + 9 * p.Scale, p.Y), p.contentManager, 4, 15, "blood", 32);
                                    p.DX = 4f;
                                    p.Push = true;
                                    p.Hitpoints -= random.Next(minZombieDmg, maxZombieDmg);
                                    sounds.PlayHurt(p, z);
                                    z.realoadTime = 0.0f;
                                }
                            }

                            if (z.DX < 0 && p.DX < 0 && !p.Push)
                                z.X = p.X - 15 * z.Scale;
                            else if (z.DX > 0 && p.DX > 0 && !p.Push)
                                z.X = p.X + 12 * z.Scale;
                        }
                        else
                            z.Collide = false;
                    }
        }
Example #4
0
        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;
                }
            }
        }
Example #5
0
 private void RemoveRocket(ExplosionHandler explosions, SoundHandler sounds, Player p)
 {
     foreach(Rocket r in this.rockets)
     {
         if (!r.Visible)
         {
             sounds.PlayExplosion(p, r);
             explosions.AddExplosion(r.Position, contentManager, 5, 15, "explosion", 32); //each time rocket is removed, explosion is created
             rockets.Remove(r);
             break;
         }
     }
 }
Example #6
0
 private void RemoveBullets(ExplosionHandler explosions)
 {
     foreach (Bullet b in bullets)
         if (!b.Visible)
         {
             bullets.Remove(b);
             if (b.SprayBlood)
                 explosions.AddExplosion(b.Position, contentManager, 4, 15, "blood", 32);
             break;
         }
 }