Esempio n. 1
0
        public void HandleDoorCollision(Player p, EnemyHandler e)
        {
            playerRectangle = new Rectangle((int)(p.X + 16 * p.Scale), (int)(p.Y + 1 * p.Scale), (int)(27 * p.Scale), (int)(63 * p.Scale));
            foreach (FlashDoor f in e.doors)
            {
                if (f.Switch)
                {
                    doorRectangle_L = new Rectangle((int)f.Position.X + 28, (int)f.Position.Y + 11, 4, 122); //left side of door laser beam
                    doorRectangle_R = new Rectangle((int)f.Position.X + 32, (int)f.Position.Y + 11, 4, 122); //right side of door laser beam
                    if (doorRectangle_L.Intersects(playerRectangle))
                    {
                        p.Hitpoints -= random.Next(minDoorDmg, maxDoorDmg);
                        p.DX = -4; //push to the left
                        p.Push = true;
                    }
                    else if (doorRectangle_R.Intersects(playerRectangle))
                    {
                        p.Hitpoints -= random.Next(minDoorDmg, maxDoorDmg);
                        p.DX = 4; //push to the right
                        p.Push = true;
                    }
                }

                switchRectangle = new Rectangle((int)f.SPosition.X + 24, (int)f.SPosition.Y + 24, 16, 16);
                if (playerRectangle.Intersects(switchRectangle) && p.IntersectWithSwitch == null)
                    p.IntersectWithSwitch = f;

                if (!playerRectangle.Intersects(switchRectangle) && p.IntersectWithSwitch == f)
                    p.IntersectWithSwitch = null;
            }
        }
Esempio n. 2
0
 public void HandleBulletZombieCollision(Player p, EnemyHandler e)
 {
     foreach (Bullet b in p.bullets)
         if (b.Visible)
         {
             bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
             foreach (ZombieDispenser zd in e.zombies)
                 foreach (Zombie z in zd.zombies)
                     if (z.Visible)
                     {
                         zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 19 * z.Scale), (int)(28 * z.Scale), (int)(45 * z.Scale));
                         zombieHeadRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 4 * z.Scale), (int)(22 * z.Scale), (int)(15 * z.Scale));
                         if (bulletRectangle.Intersects(zombieRectangle))
                         {
                             z.Hitpoints -= bulletDmg;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                         else if(bulletRectangle.Intersects(zombieHeadRectangle))
                         {
                             z.Hitpoints = 0;
                             p.Score += 5;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                     }
         }
 }
Esempio n. 3
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);
             }
     }
 }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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;
                        }
                }
        }
Esempio n. 6
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;
                    }
        }
Esempio n. 7
0
        public void HandleRocketCollision(Player p, EnemyHandler e)
        {
            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)(45 * p.Scale))
                                             : new Rectangle((int)(p.X + 24 * p.Scale), (int)p.Y, (int)(9 * p.Scale), (int)(60 * p.Scale));

            }
            foreach (Tower t in e.towers)
                foreach (Rocket r in t.rockets)
                    if (r.Visible)
                    {
                        rocketRectangle = new Rectangle((int)r.X, (int)r.Y, 3, 3);
                        if (playerRectangle.Intersects(rocketRectangle))
                        {
                            r.Visible = false;
                            p.Push = true;

                            if(r.DX > 0)
                                p.DX = 3.5f;
                            else
                                p.DX = -3.5f;

                            p.Hitpoints -= random.Next(minRocketDmg, maxRocketDmg);
                        }

                        foreach(ZombieDispenser zd in e.zombies)
                            foreach(Zombie z in zd.zombies)
                                if (z.Visible && r.Visible)
                                {
                                    zombieRectangle = new Rectangle((int)(z.X + 24 * z.Scale), (int)z.Y, (int)(16 * z.Scale), (int)(60 * z.Scale));
                                    if(rocketRectangle.Intersects(zombieRectangle))
                                    {
                                        r.Visible = false;
                                        z.Hitpoints = 0;
                                    }
                                }
                    }
        }