示例#1
0
 public void CheckZombieCollision()
 {
     if (!paused)
     {
         if (DamageDelay > 10)
         {
             for (int j = 0; j < SpawnCount; j++)
             {
                 {
                     if (Zombies[j] != null)
                     {
                         if (CollisionDetection2D.BoundingRectangleNR((int)Player.X - (int)Zombies[j].Origin.X, (int)Player.Y - (int)Zombies[j].Origin.Y, Player.Height, Player.Width, (int)Zombies[j].X, (int)Zombies[j].Y, Zombies[j].Height, Zombies[j].Width))
                         {
                             if (CollisionDetection2D.PerPixelWR(Player.Image, Zombies[j].Image, new Vector2(Player.X, Player.Y), new Vector2(Zombies[j].X, Zombies[j].Y), Player.Origin, Zombies[j].Origin, Player.RectanglePoints, Zombies[j].RectanglePoints, (float)Player.Angle, (float)Zombies[j].Angle, spriteBatch))
                             {
                                 Player.DecreaseHealth();
                                 if (!Player.Alive)
                                 {
                                     paused = true;
                                 }
                                 particleEngine.TotalParticles  = 10;
                                 particleEngine.EmitterLocation = new Vector2(Player.X, Player.Y);
                                 DamageDelay = 0;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public void CheckBulletCollision()
 {
     if (!paused)
     {
         for (int i = 0; i < Player.CurrentBullet; i++)
         {
             for (int j = 0; j < SpawnCount; j++)
             {
                 if (Player.Bullet[i] != null)
                 {
                     if (Zombies[j] != null)
                     {
                         if (CollisionDetection2D.BoundingRectangleNR((int)Zombies[j].X - (int)Player.Origin.X, (int)Zombies[j].Y - (int)Player.Origin.Y, Zombies[j].Height, Zombies[j].Width, (int)Player.Bullet[i].X, (int)Player.Bullet[i].Y, Player.Bullet[i].Height, Player.Bullet[i].Width))
                         {
                             if (CollisionDetection2D.PerPixelWR(Zombies[j].Image, Bullet, new Vector2(Zombies[j].X, Zombies[j].Y), new Vector2(Player.Bullet[i].X, Player.Bullet[i].Y), Zombies[j].Origin, Player.Bullet[i].Origin, Zombies[j].RectanglePoints, Player.Bullet[i].RectanglePoints, (float)Zombies[j].Angle, (float)Player.Bullet[i].Angle, spriteBatch))
                             {
                                 Zombies[j].DecreaseHealth();
                                 if (!Zombies[j].Alive)
                                 {
                                     ZombieDeath.Play();
                                     ZombieBodies.Add(new Zombie(Player, ScreenSize, false, content));
                                     ZombieBodies[BodiesCount].X     = Zombies[j].X;
                                     ZombieBodies[BodiesCount].Y     = Zombies[j].Y;
                                     ZombieBodies[BodiesCount].Angle = Zombies[j].Angle;
                                     BodiesCount++;
                                     Zombies.Remove(Zombies[j]);
                                     SpawnCount--;
                                 }
                                 particleEngine.UpdateBullet(Player.Bullet[i]);
                                 particleEngine.TotalParticles  = 20;
                                 particleEngine.EmitterLocation = new Vector2(Player.Bullet[i].X, Player.Bullet[i].Y);
                                 Player.Bullet[i] = null;
                             }
                         }
                     }
                 }
             }
         }
     }
 }