/// <summary> /// Check if Collision occurs between Meteor and Bullet /// Also spawn addition Meteors /// </summary> /// <param name="Lmeteor">Meteor List</param> /// <param name="Lbullet">Weapon List</param> public void DidCollisionOccur(List <Meteor> Lmeteor, List <Weapon> Lbullet) { hasHitMeteorThisCycle = false; for (int i = Lmeteor.Count - 1; i >= 0; i--) { if (!Lmeteor[i].IsDying) { for (int j = Lbullet.Count - 1; j >= 0; j--) { if (Lbullet[j].IsDying) { Lbullet[j].IsActive = false; UsedBullets.Add(Lbullet[j]); } else if (Check(Lmeteor[i].Bounds, Lbullet[j].Bounds)) { if (Settings.debug) { Lmeteor[i].isCollided = true; Lbullet[j].isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = false; Lbullet[j].isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lmeteor[i], Lbullet[j])) { int p = i; int q = j; try { Threads.InternalCollTasks.Add(Task.Run(() => bulletHitMeteor(Lmeteor[p], Lbullet[q]))); } catch { } //bulletHitMeteor(Lmeteor[i], Lbullet[j]); hasHitMeteorThisCycle = true; } } else { int p = i; int q = j; try { Threads.InternalCollTasks.Add(Task.Run(() => bulletHitMeteor(Lmeteor[p], Lbullet[q]))); } catch { } //bulletHitMeteor(Lmeteor[i], Lbullet[j]); hasHitMeteorThisCycle = true; } } if (hasHitMeteorThisCycle) { break; } } } if (hasHitMeteorThisCycle) { break; } } }
/// <summary> /// Checks collisions between the meteors and the alien bullets (they just bounce off) /// </summary> /// <param name="Lmeteor">Meteor list</param> /// <param name="Lbullet">Alien's bullet list</param> public void DidCollisionOccurNoDamage(List <Meteor> Lmeteor, List <Weapon> Lbullet) { hasBouncedThisCycle = false; for (int i = Lmeteor.Count - 1; i >= 0; i--) { if (!Lmeteor[i].IsDying) { for (int j = Lbullet.Count - 1; j >= 0; j--) { if (Lbullet[j].IsDying) { Lbullet[j].IsActive = false; UsedBullets.Add(Lbullet[j]); } else if (Check(Lmeteor[i].Bounds, Lbullet[j].Bounds)) { if (Settings.debug) { Lmeteor[i].isCollided = true; Lbullet[j].isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = false; Lbullet[j].isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lmeteor[i], Lbullet[j])) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = true; Lbullet[j].isCollidedFoReal = true; } Lbullet[j].Velocity.setVector(Lbullet[j].Velocity.getMagnitude(), Lbullet[j].Position.getDirectionFrom(Lmeteor[i].Position)); } } else { Lbullet[j].Velocity.setVector(Lbullet[j].Velocity.getMagnitude(), Lbullet[j].Position.getDirectionFrom(Lmeteor[i].Position)); } hasBouncedThisCycle = true; } if (hasBouncedThisCycle) { break; } } } if (hasBouncedThisCycle) { break; } } }
/// <summary> /// Checks collisions between the meteors and an alien ship /// </summary> /// <param name="Lmeteor">list of meteors</param> /// <param name="ship">alien ship</param> public void DidCollisionOccur(List <Meteor> Lmeteor, AlienBase ship) { for (int i = Lmeteor.Count - 1; i >= 0; i--) { if (!Lmeteor[i].IsDying) { if (Check(Lmeteor[i].Bounds, ship.Bounds)) { if (Settings.debug) { Lmeteor[i].isCollided = true; ship.isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = false; ship.isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lmeteor[i], ship)) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = true; ship.isCollidedFoReal = true; } ship.IsDying = true; DestroyedAliens.Add(ship); } } else { ship.IsDying = true; DestroyedAliens.Add(ship); } } else if (Check(Lmeteor[i].Bounds, ship.Aware)) { ship.Visibles.Add(Lmeteor[i]); } } } }
/// <summary> /// checks collisions between the player's bullets and the alien ships /// </summary> /// <param name="Lbullet">player's bullets</param> /// <param name="ship">alien ship</param> public void DidCollisionOccur(List <Weapon> Lbullet, AlienBase ship) { for (int i = Lbullet.Count - 1; i >= 0; i--) { if (!Lbullet[i].IsDying) { if (Check(Lbullet[i].Bounds, ship.Bounds)) { if (Settings.debug) { Lbullet[i].isCollided = true; ship.isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lbullet[i].isCollidedFoReal = false; ship.isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lbullet[i], ship)) { if (Settings.debug) { Lbullet[i].isCollidedFoReal = true; ship.isCollidedFoReal = true; } bulletHitAlien(ship, Lbullet[i]); } } else { bulletHitAlien(ship, Lbullet[i]); } } else if (Check(Lbullet[i].Bounds, ship.Aware)) { ship.Visibles.Add(Lbullet[i]); } } } }
/// <summary> /// Checks collisions between the aliens' bullets and the player's ship /// </summary> /// <param name="Lbullet">alien bullet list</param> /// <param name="ship">player's ship</param> public void DidCollisionOccur(List <Weapon> Lbullet, PlayerShip ship) { for (int i = Lbullet.Count - 1; i >= 0; i--) { if (!Lbullet[i].IsDying) { if (Check(Lbullet[i].Bounds, ship.Bounds)) { if (Settings.debug) { Lbullet[i].isCollided = true; ship.isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lbullet[i].isCollidedFoReal = false; ship.isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lbullet[i], ship)) { if (Settings.debug) { Lbullet[i].isCollidedFoReal = true; ship.isCollidedFoReal = true; } Lbullet[i].IsDying = true; UsedBullets.Add(Lbullet[i]); ship.IsDying = true; } } else { Lbullet[i].IsDying = true; UsedBullets.Add(Lbullet[i]); ship.IsDying = true; } } } } }
/// <summary> /// Check if Collision occurs between Meteor and playerShip /// </summary> /// <param name="Lmeteor">Meteor List</param> /// <param name="ship">Vehicle Object</param> public void DidCollisionOccur(List <Meteor> Lmeteor, PlayerShip ship) { ship.isCollided = false; for (int i = Lmeteor.Count - 1; i >= 0; i--) { Lmeteor[i].isCollided = false; if (!Lmeteor[i].IsDying) { if (Check(Lmeteor[i].Bounds, ship.Bounds)) { if (Settings.debug) { Lmeteor[i].isCollided = true; ship.isCollided = true; } if (Settings.useFancyCollisions) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = false; ship.isCollidedFoReal = false; } if (FancyCollisions.isColliding(Lmeteor[i], ship)) { if (Settings.debug) { Lmeteor[i].isCollidedFoReal = true; ship.isCollidedFoReal = true; } Lmeteor[i].IsDying = true; ship.IsDying = true; } } else { Lmeteor[i].IsDying = true; ship.IsDying = true; } } } } }