Example #1
0
 // Checking collisions between the enemy boss's projectiles and player
 public override void Collide(GameObjectDynamic obj)
 {
     for (int i = 0; i < bulletsR.Length; ++i)
     {
         if (bulletsR[i].IsAlive && obj.IsAlive)
         {
             if ((bulletsR[i].X >= obj.X - 1 && bulletsR[i].X <= obj.X + 2) && bulletsR[i].Y >= obj.Y)
             {
                 if (obj.NumLives > 0)
                 {
                     obj.NumLives       -= 1;
                     bulletsR[i].IsAlive = false;
                 }
             }
         }
     }
     for (int i = 0; i < bulletsL.Length; ++i)
     {
         if (bulletsL[i].IsAlive && obj.IsAlive)
         {
             if ((bulletsL[i].X >= obj.X - 1 && bulletsL[i].X <= obj.X + 2) && bulletsL[i].Y >= obj.Y)
             {
                 if (obj.NumLives > 0)
                 {
                     obj.NumLives       -= 1;
                     bulletsL[i].IsAlive = false;
                 }
             }
         }
     }
 }
Example #2
0
 public override void Collide(GameObjectDynamic[] objs, GameObjectDynamic obj)
 {
     //CollideProjectiles(objs);
     for (int i = 0; i < objs.Length; ++i)
     {
         if ((this != null && objs[i] != null) && (IsAlive && objs[i].IsAlive))
         {
             // I think that hardcoding is the best way for this game to detect collisions
             if ((X == objs[i].X && Y == objs[i].Y) || ((X + 1) == objs[i].X && Y == objs[i].Y) ||
                 ((X + 2) == objs[i].X && Y == objs[i].Y) || ((X) == (objs[i].X + 1) && Y == objs[i].Y) ||
                 ((X == (objs[i].X + 2)) && (Y == objs[i].Y)))
             {
                 if (NumLives > 0)
                 {
                     //this.Alive = false;
                     NumLives       -= 1;
                     objs[i].IsAlive = false;
                 }
                 else
                 {
                     IsAlive = false;
                     break;
                 }
             }
         }
     }
     if (IsAlive)
     {
         Collide(bullets, objs);
         // collide with boss
         for (int i = 0; i < bullets.Length; ++i)
         {
             if (bullets[i].IsAlive && obj.IsAlive)
             {
                 if ((bullets[i].X >= obj.X && bullets[i].X <= obj.X + 15) && bullets[i].Y <= obj.Y + 7)
                 {
                     if (obj.NumLives > 0)
                     {
                         obj.NumLives      -= 1;
                         score.Points      += 200;
                         bullets[i].IsAlive = false;
                     }
                 }
             }
         }
     }
 }