public Bullet(Bullet bullet, float degree) { //This is a shrapnel //add new bullets in random velocities OwnerName = bullet.OwnerName; PenetratingLevel = bullet.PenetratingLevel; ShrapnelLevel = bullet.ShrapnelLevel; PositionX = bullet.PositionX; PositionY = bullet.PositionY; VelocityX = bullet.VelocityX + (float)(Math.Cos(degree) * 100); VelocityY = bullet.VelocityY + (float)(Math.Sin(degree) * 100); Color = Color.White; Scale = 0.5f; Lifetime = 1; Damage = 5; IsShrapnel = true; }
public void AddBullet(Player player) { for (int i = 0; i < player.NumberOfMounts + 1; i++) { float degree = (float)((((player.Angle - (15f * player.NumberOfMounts / 2) + (15f * i)) - 90) / 180) * Math.PI); Bullet bullet = new Bullet(player, degree); Bullets.Add(bullet); } }
public void HandleBullets(Bullet bullet, ObjectManager objectManager, float frameDeltaTime) { if (bullet.Damage <= 0) { return; } foreach (var asteroid in _asteroidsInCell) { if (asteroid.HP <= 0 || asteroid.ImpactedBullets.Contains(bullet)) { continue; //This asteroid was destroyed, or already impacted by this bullet, skip checking } float tx1 = bullet.PositionX + bullet.VelocityX * frameDeltaTime; float ty1 = bullet.PositionY + bullet.VelocityY * frameDeltaTime; float tx2 = asteroid.PositionX + asteroid.VelocityX * frameDeltaTime; float ty2 = asteroid.PositionY + asteroid.VelocityY * frameDeltaTime; float rx = tx2 - tx1; float ry = ty2 - ty1; if ((float)Math.Sqrt(rx * rx + ry * ry) < (asteroid.Radius)) //bullet impact! { float damageDone = asteroid.HP; asteroid.HP -= bullet.Damage; damageDone -= asteroid.HP; asteroid.ImpactedBullets.Add(bullet); if (asteroid.HP <= 0) { damageDone += asteroid.HP; //Give money to player who shot it int value; switch (asteroid.AsteroidType) { case AsteroidType.GENERIC: value = 15; break; case AsteroidType.CLUMPY: value = 10; break; case AsteroidType.MAGNETIC: value = 50; break; case AsteroidType.REPULSER: value = 30; break; case AsteroidType.GRAVITIC: value = 40; break; case AsteroidType.DENSE: value = 30; break; case AsteroidType.ZIPPY: value = 15; break; case AsteroidType.EXPLOSIVE: value = 40; break; case AsteroidType.BLACK: value = 30; break; case AsteroidType.GOLD: value = 200; break; default: value = 50; break; } if (PlayerIsOwedMoney != null) { PlayerIsOwedMoney(bullet.OwnerName, value * asteroid.Size); } } bullet.Damage -= damageDone * (1 - (bullet.PenetratingLevel * 0.10f)); objectManager.AddExplosion(bullet.PositionX, bullet.PositionY, asteroid.VelocityX, asteroid.VelocityY, 1); } } }