Example #1
0
        /// <summary>
        /// A library function which creates a "explosion" particle effect (bouncy particles)
        /// </summary>
        /// <param name="assetName">Particle texture name</param>
        /// <param name="name">Name of the effect</param>
        /// <returns>A particle emitter which behaves like an explosion.</returns>
        public ParticleEffect CreateGenericExplosion(string assetName, string name)
        {
            List <Point> frm = new List <Point>
            {
                new Point(0, 0)
            };
            Texture2D   tex      = TextureManager.GetTexture(assetName);
            EmitterData testData = new EmitterData
            {
                Animation         = new Animation(GameState.Game.GraphicsDevice, new SpriteSheet(assetName), assetName, tex.Width, tex.Height, frm, true, Color.White, 1.0f, 1.0f, 1.0f, false),
                ConstantAccel     = new Vector3(0, -10, 0),
                LinearDamping     = 0.9999f,
                AngularDamping    = 0.9f,
                EmissionFrequency = 50.0f,
                EmissionRadius    = 1.0f,
                EmissionSpeed     = 5.0f,
                GrowthSpeed       = -0.0f,
                MaxAngle          = 3.14159f,
                MinAngle          = 0.0f,
                MaxParticles      = 1000,
                MaxScale          = 0.2f,
                MinScale          = 0.1f,
                MinAngular        = -5.0f,
                MaxAngular        = 5.0f,
                ParticleDecay     = 0.5f,
                ParticlesPerFrame = 0,
                ReleaseOnce       = true,
                Texture           = tex,
                CollidesWorld     = true,
                Sleeps            = true
            };

            RegisterEffect(name, testData);
            return(Effects[name]);
        }
Example #2
0
        public ParticleEmitter(GraphicsDevice Device, ComponentManager manager, string name, Matrix localTransform, EmitterData emitterData) :
            base(manager, name, localTransform, Vector3.Zero, Vector3.Zero, false)
        {
            Particles = new List <Particle>();

            if (emitterData == null)
            {
                return;
            }
            Data         = emitterData;
            maxParticles = Data.MaxParticles;
            Sprites      = new List <FixedInstanceArray>();
            for (var t = 0; t < Data.Animation.GetFrameCount(); ++t)
            {
                var primitive = new BillboardPrimitive();
                Data.Animation.UpdatePrimitive(primitive, t);
                Sprites.Add(new FixedInstanceArray(Name, primitive,
                                                   Data.Animation.SpriteSheet.GetTexture(),
                                                   Data.MaxParticles, Data.BlendMode));
            }
            AnimPlayer.Play(Data.Animation);

            TriggerTimer = new Timer(Data.EmissionFrequency, Data.ReleaseOnce);

            SetFlag(Flag.ShouldSerialize, false);
        }
Example #3
0
        /// <summary>
        /// Creates a generic particle effect which is like a "puff" (cloudy particles which float)
        /// </summary>
        public static EmitterData CreatePuffLike(string name, SpriteSheet sheet, Point frame, BlendState state)
        {
            Texture2D   tex  = TextureManager.GetTexture(sheet.AssetName);
            EmitterData data = new EmitterData
            {
                Animation = new Animation(GameState.Game.GraphicsDevice, sheet, name, sheet.FrameWidth, sheet.FrameHeight, new List <Point>()
                {
                    frame
                }, true, Color.White, 1.0f, 1.0f, 1.0f, false),
                ConstantAccel     = new Vector3(0, 3, 0),
                LinearDamping     = 0.9f,
                AngularDamping    = 0.99f,
                EmissionFrequency = 20.0f,
                EmissionRadius    = 1.0f,
                EmissionSpeed     = 2.0f,
                GrowthSpeed       = -0.6f,
                MaxAngle          = 3.14159f,
                MinAngle          = 0.0f,
                MaxParticles      = 1000,
                MaxScale          = 1.0f,
                MinScale          = 0.1f,
                MinAngular        = -5.0f,
                MaxAngular        = 5.0f,
                ParticleDecay     = 0.8f,
                ParticlesPerFrame = 0,
                ReleaseOnce       = true,
                Texture           = TextureManager.GetTexture(sheet.AssetName),
                Blend             = state
            };

            return(data);
        }
Example #4
0
        public ParticleEmitter(ComponentManager manager, string name, GameComponent parent, Matrix localTransform, EmitterData emitterData) :
            base(name, parent, localTransform, Vector3.Zero, Vector3.Zero, false)
        {
            Particles = new List <Particle>();

            if (emitterData == null)
            {
                return;
            }
            Data         = emitterData;
            maxParticles = Data.MaxParticles;
            Sprites      = new FixedInstanceArray(name, Data.Animation.Primitives[0], emitterData.Texture, Data.MaxParticles, Data.Blend);
            Data.Animation.Play();

            TriggerTimer = new Timer(Data.EmissionFrequency, Data.ReleaseOnce);
        }
Example #5
0
        public EmitterData Clone(SpriteSheet sheet, Point frame)
        {
            EmitterData toReturn = Clone() as EmitterData;

            if (toReturn == null)
            {
                return(null);
            }
            if (toReturn.Animation != null)
            {
                toReturn.Animation = new Animation(GameState.Game.GraphicsDevice,
                                                   new SpriteSheet(sheet.AssetName), sheet.AssetName, sheet.FrameWidth, sheet.FrameHeight,
                                                   new List <Point>()
                {
                    frame
                }, true, Color.White, 1.0f, 1.0f, 1.0f, false);
            }
            return(toReturn);
        }
Example #6
0
        public static Matrix MatrixFromParticle(EmitterData data, Particle particle)
        {
            if (!data.FixedRotation)
            {
                Matrix rot         = Matrix.CreateRotationZ(particle.Angle);
                Matrix bill        = Matrix.CreateBillboard(particle.Position, _camera.Position, _camera.UpVector, null);
                Matrix noTransBill = bill;
                noTransBill.Translation = Vector3.Zero;

                Matrix worldRot = Matrix.CreateScale(particle.Scale) * rot * noTransBill;
                worldRot.Translation = bill.Translation;
                return(worldRot);
            }
            else
            {
                Vector3 up       = Math.Abs(Vector3.Dot(particle.Direction, Vector3.Up)) > 0.9 ? Vector3.UnitZ : Vector3.Up;
                Matrix  toReturn = Matrix.CreateLookAt(Vector3.Zero, particle.Direction, up);
                toReturn.Translation = particle.Position;
                return(toReturn);
            }
        }
Example #7
0
        public ParticleEmitter(ComponentManager manager, string name, Matrix localTransform, EmitterData emitterData)
        {
            Particles = new List <Particle>();

            if (emitterData == null)
            {
                return;
            }
            Data         = emitterData;
            maxParticles = Data.MaxParticles;
            Sprites      = new List <FixedInstanceArray>();
            for (var t = 0; t < Data.Animation.GetFrameCount(); ++t)
            {
                var primitive = new BillboardPrimitive();
                Data.Animation.UpdatePrimitive(primitive, t);
                Sprites.Add(new FixedInstanceArray(name, primitive,
                                                   Data.Animation.SpriteSheet.AssetName,
                                                   Data.MaxParticles, Data.BlendMode));
            }
            AnimPlayer.Play(Data.Animation);

            TriggerTimer = new Timer(Data.EmissionFrequency, Data.ReleaseOnce);
        }
Example #8
0
        public static EmitterData CreateExplosionLike(string name, SpriteSheet sheet, Point frame, BlendState state)
        {
            Texture2D tex = TextureManager.GetTexture(sheet.AssetName);
            EmitterData data = new EmitterData
            {
                Animation = new Animation(GameState.Game.GraphicsDevice, sheet, name, sheet.FrameWidth, sheet.FrameHeight, new List<Point>() { frame }, true, Color.White, 1.0f, 1.0f, 1.0f, false),
                ConstantAccel = new Vector3(0, -10, 0),
                LinearDamping = 0.9999f,
                AngularDamping = 0.9f,
                EmissionFrequency = 50.0f,
                EmissionRadius = 1.0f,
                EmissionSpeed = 5.0f,
                GrowthSpeed = -0.0f,
                MaxAngle = 3.14159f,
                MinAngle = 0.0f,
                MaxParticles = 1000,
                MaxScale = 0.2f,
                MinScale = 0.1f,
                MinAngular = -5.0f,
                MaxAngular = 5.0f,
                ParticleDecay = 0.5f,
                ParticlesPerFrame = 0,
                ReleaseOnce = true,
                Texture = tex,
                CollidesWorld = true,
                Sleeps = true,
                Damping = 0.1f
            };

            return data;
        }
Example #9
0
        /// <summary>
        /// A library function which creates a "explosion" particle effect (bouncy particles)
        /// </summary>
        /// <param name="assetName">Particle texture name</param>
        /// <param name="name">Name of the effect</param>
        /// <returns>A particle emitter which behaves like an explosion.</returns>
        public ParticleEffect CreateGenericExplosion(string assetName, string name)
        {
            List<Point> frm = new List<Point>
            {
                new Point(0, 0)
            };
            Texture2D tex = TextureManager.GetTexture(assetName);
            EmitterData testData = new EmitterData
            {
                Animation = new Animation(GameState.Game.GraphicsDevice, new SpriteSheet(assetName), assetName, tex.Width, tex.Height, frm, true, Color.White, 1.0f, 1.0f, 1.0f, false),
                ConstantAccel = new Vector3(0, -10, 0),
                LinearDamping = 0.9999f,
                AngularDamping = 0.9f,
                EmissionFrequency = 50.0f,
                EmissionRadius = 1.0f,
                EmissionSpeed = 5.0f,
                GrowthSpeed = -0.0f,
                MaxAngle = 3.14159f,
                MinAngle = 0.0f,
                MaxParticles = 1000,
                MaxScale = 0.2f,
                MinScale = 0.1f,
                MinAngular = -5.0f,
                MaxAngular = 5.0f,
                ParticleDecay = 0.5f,
                ParticlesPerFrame = 0,
                ReleaseOnce = true,
                Texture = tex,
                CollidesWorld = true,
                Sleeps = true
            };

            RegisterEffect(name, testData);
            return Effects[name];
        }
Example #10
0
        public ParticleEmitter(ComponentManager manager, string name, GameComponent parent, Matrix localTransform, EmitterData emitterData)
            : base(name, parent, localTransform, Vector3.Zero, Vector3.Zero, false)
        {
            Particles = new List<Particle>();

            if(emitterData == null)
            {
                return;
            }

            Data = emitterData;
            maxParticles = Data.MaxParticles;
            Sprites = new FixedInstanceArray(name, Data.Animation.Primitives[0], emitterData.Texture, Data.MaxParticles, Data.Blend);
            Data.Animation.Play();

            TriggerTimer = new Timer(Data.EmissionFrequency, Data.ReleaseOnce);
        }