Пример #1
0
 internal void Subscribe(Emitter emitter)
 {
     if (!_subscriptions.Contains(emitter))
     {
         _subscriptions.Add(emitter);
     }
 }
Пример #2
0
 internal void UnSubscribe(Emitter emitter)
 {
     if (_subscriptions.Contains(emitter))
     {
         _subscriptions.Remove(emitter);
     }
 }
        /// <summary>
        /// Processes an Emitter.
        /// </summary>
        /// <param name="time">Game timing data.</param>
        /// <param name="controlled">MercuryParticleEngine.Emitters.Emitter object to process.</param>
        public override void ProcessEmitter(GameTime time, Emitter controlled)
        {
            MouseState state = Mouse.GetState();

            controlled.Position.X = (float)state.X;
            controlled.Position.Y = (float)state.Y;

            switch (_button)
            {
                case MouseButtons.Left:
                    {
                        if (state.LeftButton == ButtonState.Pressed)
                            controlled.Trigger();
                        break;
                    }
                case MouseButtons.Middle:
                    {
                        if (state.MiddleButton == ButtonState.Pressed)
                            controlled.Trigger();
                        break;
                    }
                case MouseButtons.Right:
                    {
                        if (state.RightButton == ButtonState.Pressed)
                            controlled.Trigger();
                        break;
                    }
            }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="emitter">Emitter to trail</param>
        /// <param name="frequency">Frequency to trigger</param>
        public TrailController(Emitter emitter, int frequency)
        {
            AutoResetEvent autoReset = new AutoResetEvent(false);
            TimerCallback timerDelegate = new TimerCallback(Tick);

            _emitter = emitter;
            _timer = new Timer(timerDelegate, autoReset, 0, frequency);
        }
 public override void UpdateEmitter(GameTime time, Emitter emitter)
 {
     if (_primed)
     {
         emitter.Trigger();
         _primed = false;
     }
 }
Пример #6
0
        public void AddEmitter(Emitter emitter)
        {
            _emitters.Add(emitter);

            foreach (Modifier mod in _modifiers)
            {
                emitter.ApplyModifier(mod);
            }
        }
Пример #7
0
        protected override void Initialize()
        {
            base.Initialize();

            emitter = new Emitter(1000);
            emitter.ParticleLifespan = 2000;
            emitter.ParticleSpeed = 150f;
            emitter.ParticleSpeedRange = 50f;

            //We have seen some examples of Modifiers in the previous examples. Modifiers
            //are always necessary to bring Emitters to life, but there is no limit to the
            //amount, and variety of Modifiers you can apply.
            emitter.ApplyModifier(new EmitterMouseController(false));
            emitter.ApplyModifier(new TimedTriggerController(10f));

            //There are many Modifiers to choose from to get the effect you desire, and it
            //is easy to create you own (there will be another example of this). Here i will
            //demonstrate some of the most useful Modifiers.

            //The GravityModifier applys a linear gravity force to all active Particles. You
            //can adjust the direction, and the strength of gravity.
            emitter.ApplyModifier(new GravityModifier(MathHelper.PiOver2, 350f));

            //The Color3Modifier fades the color of Particles between 3 colors. You can
            //adjust the sweep rate of the middle color. The interpolation is pre-calculated,
            //and you can change the smoothness of the pre-calculation (higher is better).
            emitter.ApplyModifier(new Color3Modifier(Color.White.ToVector3(),
                Color.SteelBlue.ToVector3(), 0.25f, Color.Purple.ToVector3(), 128));

            //Also available is a Color2Modifier, which fades between 2 colors - this is not
            //pre-calculated and so you can change the colors in realtime.
            //Plus, there is a RandomColorModifier, which gives each spawned Particle a
            //random color.

            //As well as color, there are similar Modifiers for adjusting Particles opacity
            //and scale. They work in the same way. There is the addition of MultiOpacity
            //and MultiScale Modifiers, which interpolate between and infinate number of
            //values...
            emitter.ApplyModifier(new Scale2Modifier(0f, 3f));
            emitter.ApplyModifier(new Opacity3Modifier(1f, 1f, 0.75f, 0f, 64));

            //The AtmosphereModifier allows you to simulate dense atmosphere of water. It
            //works by adjusting the speed of the Particles as they move... A density of 1
            //will have no effect on the Particles. A density >1 has the effect of slowing
            //Particles.
            emitter.ApplyModifier(new AtmosphereModifier(1.2f));

            //Finally, the WindowBounceModifier causes Particles to bounce off the edge of
            //game window. You can adjust the bounce coefficient.
            emitter.ApplyModifier(new WindowBounceModifier(this.Window, .75f));

            //As always, we need to add the Emitter to the ParticleSystem.
            system.AddEmitter(emitter);
        }
Пример #8
0
        public bool RemoveEmitter(Emitter emitter, bool mods)
        {
            if (mods)
            {
                foreach (Modifier mod in _modifiers)
                {
                    emitter.RemoveModifier(mod);
                }
            }

            return _emitters.Remove(emitter);
        }
        /// <summary>
        /// Processes the Emitter.
        /// </summary>
        /// <param name="time">Game timing data.</param>
        /// <param name="controlled">MercuryParticleEngine.Emitters.Emitter object to process.</param>
        public override void ProcessEmitter(GameTime time, Emitter controlled)
        {
            GamePadState state = GamePad.GetState(PlayerIndex.One, GamePadDeadZone.Circular);

            if (_stick == ThumbSticks.Left)
            {
                controlled.Position.X += (state.ThumbSticks.Left.X * 32f);
                controlled.Position.Y -= (state.ThumbSticks.Left.Y * 32f);
            }
            else
            {
                controlled.Position.X += (state.ThumbSticks.Right.X * 32f);
                controlled.Position.Y -= (state.ThumbSticks.Right.Y * 32f);
            }

            switch (_button)
            {
                case Buttons.A:
                    {
                        if (state.Buttons.A == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
                case Buttons.B:
                    {
                        if (state.Buttons.B == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
                case Buttons.X:
                    {
                        if (state.Buttons.X == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
                case Buttons.Y:
                    {
                        if (state.Buttons.Y == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
                case Buttons.LB:
                    {
                        if (state.Buttons.LeftShoulder == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
                case Buttons.RB:
                    {
                        if (state.Buttons.RightShoulder == ButtonState.Pressed) { controlled.Trigger(); }
                        break;
                    }
            }
        }
        public override void UpdateEmitter(GameTime time, Emitter emitter)
        {
            MouseState state = Mouse.GetState();

            emitter.Position.X = (float)state.X;
            emitter.Position.Y = (float)state.Y;

            if (_click)
            {
                if (state.LeftButton == ButtonState.Pressed)
                {
                    emitter.Trigger();
                }
            }
        }
Пример #11
0
        protected override void Initialize()
        {
            base.Initialize();

            //When creating an Emitter, you will always need to specify a budget. The budget
            //is the number of Particles the Emittter has, and if the Emitter tries to
            //emit more than this number, it will raise a 'starving' event. (Emitter events
            //will be demonstrated in another example)
            emitter = new Emitter(1000);

            //Setting the DischargeQuantity controls how many Particles the Emitter spawns
            //each time it is triggered.
            emitter.DischargeQuantity = 3;

            //The speed of Particles is controlled with two values. The first value is the
            //base speed of all Particles, and the second value is the range either side of
            //the base speed. Each particle is assigned a random speed value between
            //Speed - (Range /2), and Speed + (Range /2).
            emitter.ParticleSpeed = 50f;
            emitter.ParticleSpeedRange = 50f;
            //So, each Particle will have a speed between 25, and 75.

            //Applying Modififiers to an Emitter is the way to advanced Emitter effects, and
            //can also help integrate the engine into your game. In this example we are
            //applying 3 simple Modifiers. The first is a MouseController, which moves the
            //position of the Emitter to match the Mouse coordinates. The MouseController
            //modifier can also trigger the Emitter when the mouse button is pressed. The
            //second is a RandomColorModifier, which causes each spawned Particle to be a
            //random color. The third is a RandomScaleModifier, which causes each Particle
            //to be a random scale between the minimum and maximum values specified.
            Modifier mouseControl = new EmitterMouseController(true);
            Modifier randomColor = new RandomColorModifier();
            Modifier randomScale = new RandomScaleModifier(.1f, 2f);

            //We must apply each of these Modifiers to the Emitter.
            emitter.ApplyModifier(mouseControl);
            emitter.ApplyModifier(randomColor);
            emitter.ApplyModifier(randomScale);

            //And finally, we must add the Emitter to the ParticleSystem.
            system.AddEmitter(emitter);

            //This demonstration is now ready to run!
        }
Пример #12
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);

            system = new ParticleSystem(this);
            emitter = new Emitter(1000);
            emitter.ParticleSpeed = 150f;
            emitter.ApplyModifier(new EmitterMouseController(true));

            //When creating an ImageStrip, you must supply 5 pieces of information. You must
            //give the ImageStrip a name, so that Emitters can identify it. You must specify
            //the number of frames in the ImageStrip, and also the width and height of each
            //frame. Finally you must specify the asset name, as specified in the content
            //pipeline.
            strip = new ImageStrip("custom");
            strip.Asset = "CustomParticleImage";
            strip.FrameHeight = 128;
            strip.FrameWidth = 128;
            strip.Frames = 4;

            //When it is done, you will add the ImageStrip to the ParticleSystem.
            system.ImageStrips.Add("custom", strip);

            //Then you will tell the Emitter to use this ImageStrip.
            emitter.ImageStrip = "custom";
            emitter.Frame = 2;

            //When using the ImageStrip, the Emitter will automatically render the
            //specified frame at the correct size, and the origin will always be at the
            //centre of the frame.

            system.AddEmitter(emitter);

            //If you make an error, either by telling the Emitter to use an ImageStrip that
            //doesn't exist, or telling it to use a frame that doesn't exist - The Emitter
            //will instead render Particles with an exclamation mark (!), to let you know
            //that there has been an error.
        }
Пример #13
0
 public bool RemoveEmitter(Emitter emitter, bool mods)
 {
     return _groups["Default"].RemoveEmitter(emitter, mods);
 }
Пример #14
0
 public void AddEmitter(Emitter emitter)
 {
     _groups["Default"].AddEmitter(emitter);
 }
Пример #15
0
 public virtual void UpdateEmitter(GameTime time, Emitter emitter) { }
Пример #16
0
        /// <summary>
        /// Adds an Emitter to the ParticleSystem.
        /// </summary>
        /// <param name="emitter">MercuryParticleEngine.Emitters.Emitter object to add.</param>
        /// <returns>True if the Emitter was successfully added, else false.</returns>
        /// <remarks>The system is smart enough to prevent the same Emitter being added
        /// multiple times.</remarks>
        public bool AddEmitter(Emitter emitter)
        {
            if (_emitters.Contains(emitter)) { return false; }

            _emitters.Add(emitter);

            _modifiers.ForEach(delegate(Modifier modifier)
            {
                emitter.ApplyModifier(modifier);
            });

            return true;
        }
Пример #17
0
 /// <summary>
 /// Process an Emitter.
 /// </summary>
 /// <param name="time">Game timing data.</param>
 /// <param name="controlled">MercuryParticleEngine.Emitters.Emitter object to process.</param>
 public virtual void ProcessEmitter(GameTime time, Emitter controlled) { }
 /// <summary>
 /// Default Constructor.
 /// </summary>
 /// <param name="emitter">Emitter whos Particles will explode on expiry.</param>
 public ExplosionController(Emitter emitter)
 {
     _emitter = emitter;
     emitter.Disposing += new EventHandler(Disposed);
 }
Пример #19
0
        /// <summary>
        /// Removes an Emitter from the ParticleSystem.
        /// </summary>
        /// <param name="emitter">MercuryParticleEngine.Emitters.Emitter object to remove.</param>
        /// <returns>True if the Emitter was successfully removed, else false.</returns>
        public bool RemoveEmitter(Emitter emitter)
        {
            if (!_emitters.Contains(emitter)) { return false; }

            _modifiers.ForEach(delegate(Modifier modifier)
            {
                emitter.RemoveModifier(modifier);
            });

            return true;
        }