private void Impact(Ship ship, Bullet bullet) { if (bullet.Owner == ship.Player) { // I own this particle, thus it won't hurt me. // Make it bounce. bullet.Velocity *= -1; try { this.bulletShipImpactBounceSound.Play(); } catch { // Must be out of sound channels. } } else { bullet.Life = 0; try { this.bulletShipImpactSound.Play(); } catch { // Must be out of sound channels. } DamageShip(ship, bullet.Power); } }
private void Impact(Planet planet, Bullet bullet) { bullet.Life = 0; try { this.bulletPlanetImpactSound.Play(); } catch { // Must be out of sound channels. } }
public Bullet Fire() { Vector shipVector = this.owner.Velocity; Sprite sprite = this.owner.Sprite; int gunDirectionDeg = this.owner.SpriteSheet.CurrentDirectionDeg; Point shipCenterPos = sprite.Center; if (this.LiveBulletCount >= Configuration.MaxLiveBulletsPerCannon) { // Too many bullets currently active for this cannon. try { this.dryFireSound.Play(); } catch { // Must be out of sound channels. } return null; } DateTime now = DateTime.Now; if (this.lastFiredTime + this.cooldown > now) // Still cooling down. return null; Point gunBarrelPos = SolidEntity.GetPosition(shipCenterPos, gunDirectionDeg, this.barrelLength); Vector bulletVector = Vector.FromDirection(gunDirectionDeg, this.muzzleSpeed); bulletVector += shipVector; Bullet cannonBullet = new Bullet(this.owner.Player, this.bulletSurface, gunBarrelPos, bulletVector, Configuration.Ships.Cannon.Power, bulletLife); /* Add the new bullet to the ship's particle collection so we can * tell it apart from bullets fired by the other ship. */ this.bulletCollection.Add(cannonBullet); this.lastFiredTime = now; try { this.fireSound.Play(); } catch { // Must be out of sound channels. } return cannonBullet; }