示例#1
0
 private void goOverdrive()
 {
     _state          = BlackHoleState.Overdrive;
     _explosionTimer = TimeSpan.FromSeconds(SECONDS_BEFORE_EXPLODE);
     _particleEffect.IntensityFactor = 3.0f;
     Gravity = new Gravity(Position, Gravity.Magnitude * 1.4f);
 }
示例#2
0
        public void Update(GameTime gameTime)
        {
            _particleEffect.Update(gameTime);
            //only spawn particles when pulling or pushing
            if (_state == BlackHoleState.Pulling || _state == BlackHoleState.Explosion || _state == BlackHoleState.Overdrive)
            {
                _particleEffect.Spawn(Position, 0.0f, gameTime.ElapsedGameTime, Vector2.Zero,
                                      1.0f + _capacityUsed / _totalCapacity); //spawn rate increases as capacity fills
            }

            if (_state == BlackHoleState.Overdrive)
            {
                _overdriveTimer -= gameTime.ElapsedGameTime;
                if (_overdriveTimer < TimeSpan.Zero)
                {
                    _state = BlackHoleState.PreExplosion;
                }
            }

            if (_state == BlackHoleState.PreExplosion || _state == BlackHoleState.Explosion)
            {
                _explosionTimer -= gameTime.ElapsedGameTime;
                if (_explosionTimer <= TimeSpan.Zero)
                {
                    if (_state == BlackHoleState.PreExplosion)
                    {
                        _state = BlackHoleState.Explosion; //start exploding
                        Gravity.MagnitudeFactor  = -3;     //go from suck to blow
                        _particleEffect.Reversed = false;  //cause particle effects to push out
                        _explosionTimer          = TimeSpan.FromSeconds(SECONDS_DURING_EXPLODE);
                    }
                    else
                    {
                        _state = BlackHoleState.Exhausted;      //stop affecting anything
                    }
                }
            }
        }
        public void Update(GameTime gameTime)
        {
            _particleEffect.Update(gameTime);
            //only spawn particles when pulling or pushing
            if (_state == BlackHoleState.Pulling || _state == BlackHoleState.Explosion || _state == BlackHoleState.Overdrive)
            {
                _particleEffect.Spawn(Position, 0.0f, gameTime.ElapsedGameTime, Vector2.Zero,
                    1.0f + _capacityUsed / _totalCapacity);   //spawn rate increases as capacity fills
            }

            if (_state == BlackHoleState.Overdrive)
            {
                _overdriveTimer -= gameTime.ElapsedGameTime;
                if (_overdriveTimer < TimeSpan.Zero)
                {
                    _state = BlackHoleState.PreExplosion;
                }
            }

            if (_state == BlackHoleState.PreExplosion || _state == BlackHoleState.Explosion)
            {
                _explosionTimer -= gameTime.ElapsedGameTime;
                if (_explosionTimer <= TimeSpan.Zero)
                {
                    if (_state == BlackHoleState.PreExplosion)
                    {
                        _state = BlackHoleState.Explosion;  //start exploding
                        Gravity.MagnitudeFactor = -3;   //go from suck to blow
                        _particleEffect.Reversed = false;     //cause particle effects to push out
                        _explosionTimer = TimeSpan.FromSeconds(SECONDS_DURING_EXPLODE);
                    }
                    else
                        _state = BlackHoleState.Exhausted;      //stop affecting anything
                }

            }
        }
 private void goOverdrive()
 {
     _state = BlackHoleState.Overdrive;
     _explosionTimer = TimeSpan.FromSeconds(SECONDS_BEFORE_EXPLODE);
     _particleEffect.IntensityFactor = 3.0f;
     Gravity = new Gravity(Position, Gravity.Magnitude * 1.4f);
 }
        /// <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);
                    }
                }
            }
        }