/// <summary> /// This method calculates Projectile and ship collision. /// </summary> /// <param name="s"></param> private static void ProjectileShipCollision(Ship s) { foreach (Projectile p in world.projectileCollection.Values.ToList()) { //if ship hp is not equal to zero. if (s.getShipHp() != 0) { //if projectile location and ship location is less than 25 and projectile is alive. if ((p.getProjectileLoc() - s.getShipLoc()).Length() < 25 && (p.getProjectileOwner() != s.getShipId())) { //get the score and hp for the owner of the projectile. int score = world.shipCollection[p.getProjectileOwner()].getShipScore(); int hp = world.shipCollection[p.getProjectileOwner()].getShipHp(); //decrement ships hp by 1. s.setShipHp(s.getShipHp() - 1); //for extra game mode. if (gameMode == 1) { //if projectile owner hp is less than 5. if (world.shipCollection[p.getProjectileOwner()].getShipHp() < 5) { //icrement the ships hp by 1, if it hits other ship. world.shipCollection[p.getProjectileOwner()].setShipHp((s.getShipHp() + 1)); } } p.setProjectileAlive(false); //id ship hp is zer0. if (s.getShipHp() == 0) { //extra game mode. if (gameMode == 1) { if (hp < 5) { //increments hp by 1. world.shipCollection[p.getProjectileOwner()].setShipHp(hp + 1); } } //increments score by 1. world.shipCollection[p.getProjectileOwner()].setShipScore(score + 1); } } } } }