/// <summary> /// Apply Gravity on a unit and eat it if close enough /// call on each unit during unit update loop /// </summary> /// <param name="unit">unit to affect. Should be called after updating unit</param> public void ApplyToUnit(PhysicalBody unit, GameTime gameTime) { float massEaten; if (_state != BlackHoleState.Pulling && _state != BlackHoleState.Overdrive) return; if (_state == BlackHoleState.Pulling) { unit.ApplyGravity(Gravity, gameTime); } else if (_state == BlackHoleState.Overdrive) { unit.FlyToPoint(Position, _overdriveTimer, 2.0f); } if ((massEaten = unit.EatByBlackHole(Position, _radius)) > 0) { _capacityUsed += massEaten; _particleEffect.IntensityFactor = 1.0f + _capacityUsed / _totalCapacity; Gravity.MagnitudeFactor = (1.0f + _capacityUsed / _totalCapacity); if (_capacityUsed > _totalCapacity) { goOverdrive(); } } }
public void CheckAndApplyCollision(PhysicalBody unit, GameTime gameTime) { switch (_state) { case State.Dormant: break; case State.Appearing: case State.Scanning: unit.ApplyGravity(_gravity, gameTime); break; case State.Charging: unit.ApplyGravity(_gravity, gameTime); if (willCollide(unit.Top, unit.Bottom, unit.Left, unit.Right, gameTime.ElapsedGameTime)) { unit.ApplyImpact(_velocity, IMPACT_IMPULSE); unit.ApplyDamage(IMPACT_DAMAGE); break; } break; } }