Example #1
0
        /// <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(PhysicalUnit 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();
                }
            }
        }
Example #2
0
        public void CheckAndApplyCollision(PhysicalUnit 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;
            }
        }
Example #3
0
 public void CheckAndApplyCollision(PhysicalUnit 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;
     }
 }
        /// <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(PhysicalUnit 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();
                }
            }
        }
        /// <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(PhysicalUnit unit, GameTime gameTime)
        {
            if (_state == BlackHoleState.Exhausted || _state == BlackHoleState.PreExplosion)
                return;

            unit.ApplyGravity(Gravity, gameTime);
            if ((Position - unit.Center).Length() <= _radius && _state == BlackHoleState.Pulling)
            {   //try to eat unit
                if (unit.EatByBlackHole())
                {
                    _capacityUsed += unit.Mass;
                    foreach (ParticleEffect p in _particleEffects)
                    {
                        p.IntensityFactor = 1.0f + _capacityUsed / _totalCapacity;
                    }
                    Gravity.MagnitudeFactor = (1.0f + _capacityUsed / _totalCapacity);
                    if (_capacityUsed > _totalCapacity)
                    {
                        _state = BlackHoleState.PreExplosion;
                        _explosionTimer = TimeSpan.FromSeconds(SECONDS_BEFORE_EXPLODE);
                    }
                }
            }
        }