bool UpdateParticle(ref CCParticleRadial particleRadial, float dt)
        {
            if(UpdateParticleBase(ref particleRadial.ParticleBase, dt))
            {
                particleRadial.Angle += particleRadial.DegreesPerSecond * dt;
                particleRadial.Radius += particleRadial.DeltaRadius * dt;

                CCPoint position = particleRadial.ParticleBase.Position;
                position.X = -CCMathHelper.Cos(particleRadial.Angle) * particleRadial.Radius;
                position.Y = -CCMathHelper.Sin(particleRadial.Angle) * particleRadial.Radius;
                particleRadial.ParticleBase.Position = position;

                return true;
            }

            return false;
        }
        public CCParticleSystem(CCParticleSystemConfig particleConfig) : this(particleConfig.MaxParticles, false)
        {
            Duration = particleConfig.Duration;;
            Life = particleConfig.Life;
            LifeVar = particleConfig.LifeVar;
            EmissionRate = TotalParticles / Life;

            Angle = particleConfig.Angle;
            AngleVar = particleConfig.AngleVar;

            CCColor4F startColor = new CCColor4F();
            startColor.R = particleConfig.StartColor.R;
            startColor.G = particleConfig.StartColor.G;
            startColor.B = particleConfig.StartColor.B;
            startColor.A = particleConfig.StartColor.A;
            StartColor = startColor;

            CCColor4F startColorVar = new CCColor4F();
            startColorVar.R = particleConfig.StartColorVar.R;
            startColorVar.G = particleConfig.StartColorVar.G;
            startColorVar.B = particleConfig.StartColorVar.B;
            startColorVar.A = particleConfig.StartColorVar.A;
            StartColorVar = startColorVar;

            CCColor4F endColor = new CCColor4F();
            endColor.R = particleConfig.EndColor.R;
            endColor.G = particleConfig.EndColor.G;
            endColor.B = particleConfig.EndColor.B;
            endColor.A = particleConfig.EndColor.A;
            EndColor = endColor;

            CCColor4F endColorVar = new CCColor4F();
            endColorVar.R = particleConfig.EndColorVar.R;
            endColorVar.G = particleConfig.EndColorVar.G;
            endColorVar.B = particleConfig.EndColorVar.B;
            endColorVar.A = particleConfig.EndColorVar.A;
            EndColorVar = endColorVar;

            StartSize = particleConfig.StartSize;
            StartSizeVar = particleConfig.StartSizeVar;
            EndSize = particleConfig.EndSize;
            EndSizeVar = particleConfig.EndSizeVar;

            CCPoint position;
            position.X = particleConfig.Position.X;
            position.Y = particleConfig.Position.Y;
            Position = position;

            CCPoint positionVar;
            positionVar.X = particleConfig.PositionVar.X;
            positionVar.Y = particleConfig.PositionVar.X;
            PositionVar = positionVar;

            StartSpin = particleConfig.StartSpin;
            StartSpinVar = particleConfig.StartSpinVar;
            EndSpin = particleConfig.EndSpin;
            EndSpinVar = particleConfig.EndSpinVar;

            EmitterMode = particleConfig.EmitterMode;

            if (EmitterMode == CCEmitterMode.Gravity)
            {
                GravityParticles = new CCParticleGravity[TotalParticles];

                GravityMoveMode newGravityMode = new GravityMoveMode();

                CCPoint gravity;
                gravity.X = particleConfig.Gravity.X;
                gravity.Y = particleConfig.Gravity.Y;
                newGravityMode.Gravity = gravity;

                newGravityMode.Speed = particleConfig.GravitySpeed;
                newGravityMode.SpeedVar = particleConfig.GravitySpeedVar;
                newGravityMode.RadialAccel = particleConfig.GravityRadialAccel;
                newGravityMode.RadialAccelVar = particleConfig.GravityRadialAccelVar;
                newGravityMode.TangentialAccel = particleConfig.GravityTangentialAccel;
                newGravityMode.TangentialAccelVar = particleConfig.GravityTangentialAccelVar;
                newGravityMode.RotationIsDir = particleConfig.GravityRotationIsDir;

                GravityMode = newGravityMode;
            }
            else if (EmitterMode == CCEmitterMode.Radius)
            {
                RadialParticles = new CCParticleRadial[TotalParticles];

                RadialMoveMode newRadialMode = new RadialMoveMode();

                newRadialMode.StartRadius = particleConfig.RadialStartRadius;
                newRadialMode.StartRadiusVar = particleConfig.RadialStartRadiusVar;
                newRadialMode.EndRadius = particleConfig.RadialEndRadius;
                newRadialMode.EndRadiusVar = particleConfig.RadialEndRadiusVar;
                newRadialMode.RotatePerSecond = particleConfig.RadialRotatePerSecond;
                newRadialMode.RotatePerSecondVar = particleConfig.RadialRotatePerSecondVar;

                RadialMode = newRadialMode;
            }
            else
            {
                Debug.Assert(false, "Invalid emitterType in config file");
                return;
            }
        }
        void InitParticle(ref CCParticleRadial particleRadial, ref CCParticleBase particleBase)
        {
            InitParticleBase(ref particleBase);

            // direction
            float a = MathHelper.ToRadians(Angle + AngleVar * CCRandom.Float_Minus1_1());

            // Set the default diameter of the particle from the source position
            float startRadius = RadialMode.StartRadius + RadialMode.StartRadiusVar * CCRandom.Float_Minus1_1();
            float endRadius = RadialMode.EndRadius + RadialMode.EndRadiusVar * CCRandom.Float_Minus1_1();

            particleRadial.Radius = startRadius;
            particleRadial.DeltaRadius = (RadialMode.EndRadius == ParticleStartRadiusEqualToEndRadius) ? 
                0 : (endRadius - startRadius) / particleBase.TimeToLive;

            particleRadial.Angle = a;
            particleRadial.DegreesPerSecond =
                MathHelper.ToRadians(RadialMode.RotatePerSecond + RadialMode.RotatePerSecondVar * CCRandom.Float_Minus1_1());
        }
        CCParticleSystem(int numberOfParticles, bool shouldAllocParticles, CCEmitterMode emitterMode = CCEmitterMode.Gravity)
        {
            TotalParticles = numberOfParticles;
            AllocatedParticles = numberOfParticles;
            PositionType = CCPositionType.Free;
            EmitterMode = emitterMode;

            IsActive = true;
            AutoRemoveOnFinish = false;

            if(shouldAllocParticles) 
            {
                if (emitterMode == CCEmitterMode.Gravity) 
                {
                    GravityParticles = new CCParticleGravity[numberOfParticles];
                } 
                else 
                {
                    RadialParticles = new CCParticleRadial[numberOfParticles];
                }
            }
        }