/// <summary> /// Initialize a bullet that has been retrieved from the pool. /// </summary> public void InitializePooledBullet(Vector2 pos, Ship parent) { _isDead = false; Position = pos; Color = Color.White; Damage = 0; ParentShip = parent; Texture = GameContent.Assets.Images.Ships.Bullets[ParentShip.ShipType, ParentShip.Tier]; _traveledDistance = Vector2.Zero; MaximumDistance = new Vector2(4000f); }
private void processShrinkBullets(Ship ship) { foreach (Bullet b in ShrinkRayBullets) { b.Color = Color.Purple; b.DoSpeedPlus(); b.MaximumDistance = new Vector2(875); if (b.MaximumDistance.HasValue) { if (b.TraveledDistance.LengthSquared() >= b.MaximumDistance.Value.LengthSquared()) { b.IsDead = true; FireKilledEvent(); } } if (!b.IsDead && b.Intersects(ship)) { if (ship.ShrinkCount < MaxShrinks) { ship.Scale *= .66f; ship.ShrinkCount++; } if (ship.CurrentHealth > 1) { ship.CurrentHealth = (ship.CurrentHealth * .66f).Round(); } else { //Ship is at 1 health - MURDER IT!!!! ship.Kill(true); } b.IsDead = true; FireKilledEvent(); } } }
/// <summary> /// Computes the distance to the nearest enemy. /// </summary> /// <returns>Whether or not an enemy is in range.</returns> private bool isEnemyDetected() { if (shipState == CoreTypes.ShipState.Dead || shipState == CoreTypes.ShipState.Exploding) { //Can't detect an enemy if dead return false; } //finds the closes ship foreach (Ship enemyShip in StateManager.EnemyShips) { if (!shipDistance.HasValue && !closestEnemyShipDistance.HasValue) { shipDistance = enemyShip.WorldCoords - this.WorldCoords; closestEnemyShipDistance = shipDistance; closestEnemyShip = enemyShip; } else { shipDistance = enemyShip.WorldCoords - this.WorldCoords; if (shipDistance.Value.LengthSquared() < closestEnemyShipDistance.Value.LengthSquared()) { closestEnemyShipDistance = shipDistance; closestEnemyShip = enemyShip; } } } return (closestEnemyShipDistance.HasValue && closestEnemyShip != null && closestEnemyShipDistance.Value.LengthSquared() < RangeSquared && closestEnemyShip.CurrentHealth > 0); }
public Bullet(Texture2D texture, Vector2 location, SpriteBatch spriteBatch, Ship parentShip) : base(texture, location, spriteBatch) { this.ParentShip = parentShip; UseCenterAsOrigin = true; }
private void checkIfShipHitMine(Ship ship) { if (ship is Drone) { if (ship.Cast<Drone>().DroneState == DroneState.Stowed || ship.Cast<Drone>().DroneState == DroneState.RIP) { return; } } if (Intersects(ship.WCrectangle)) { ship.CurrentHealth -= this.Damage; if(StateManager.Options.SFXEnabled) { ExplosionSound.Play(); } SpaceMineState = CoreTypes.SpaceMineState.RIP; } }