示例#1
0
        // Implement a ParticleRepeller class. A ParticleRepeller is a Particle, which pushes other particles away from it
        // (i.e. accelerates them in a direction, opposite of the direction in which the repeller is).
        // The repeller has an effect only on particles within a certain radius (see Euclidean distance).
        static void Main()
        {
            IRenderer renderer = new ConsoleRenderer(MaxRows, MaxCols);
            IParticleOperator particleOperator = new ParticleUpdater();

            // Add particle repeller (appears as 'R' on the console)
            MatrixCoords repellerPosition = new MatrixCoords(MaxRows * 2 / 4, MaxCols * 2 / 4);
            MatrixCoords repellerSpeed = new MatrixCoords(0, 0);
            int repellerGravity = -4; // negative for antigravity
            ParticleRepeller repeller = new ParticleRepeller(repellerPosition, repellerSpeed, repellerGravity);

            // Use a field engine - derives from Engine, but can affect the speed of the particles,
            // the center of the field is the repeller

            int sleepTimeMs = 50;
            FieldEngine engine = new FieldEngine(renderer, particleOperator, sleepTimeMs, repeller);
            engine.AddParticle(repeller);

            // Add emmitter for free particles (appears as 'E' on the console)
            MatrixCoords emitterPosition = new MatrixCoords(MaxRows / 4, MaxCols / 4);
            MatrixCoords emitterSpeed = new MatrixCoords(4, 4);
            int particleLifeTicks = 30;
            ParticleEmitter emitter = new ParticleEmitter(emitterPosition, emitterSpeed, particleLifeTicks);
            engine.AddParticle(emitter);

            SetConsole();
            engine.Run();
        }
示例#2
0
        static void GenerateInitialData(Engine engine)
        {
            var emitterPosition = new MatrixCoords(29, 0);
            var emitterSpeed = new MatrixCoords(0, 0);

            var emitter = new ParticleEmitter(emitterPosition, emitterSpeed, randGenerator, 5, 2, GenerateRandomParticle);

            engine.AddParticle(emitter);

            //check attractor
            var attractorPosition = new MatrixCoords(10, 10);

            var attractor = new ParticleAttractor(attractorPosition, new MatrixCoords(0, 0), 1);

            engine.AddParticle(attractor);

            // 02.Test the ChaoticParticle through the ParticleSystemMain class
            // Create chaotic particle and add it to the engine
            var chaoticParticle = new ChaoticParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), randGenerator);
            engine.AddParticle(chaoticParticle);

            // 04.Test the ChickenParticle class through the ParcticleSystemMain class.
            var chickenParticle = new ChickenParticle(new MatrixCoords(10, 10), new MatrixCoords(-1, 2), randGenerator, 20);
            engine.AddParticle(chickenParticle);

            // 06.Test the ParticleRepeller class through the ParticleSystemMain class
            // create repeller with large radius and power to see the result
            // because in one moment there are too many new chicken particles created
            var particleRepeller = new ParticleRepeller(new MatrixCoords(20, 20), new MatrixCoords(0, 0), 10, 20.0);
            engine.AddParticle(particleRepeller);
        }
示例#3
0
 public Particle(
     ParticleEmitter parent,
     Vector3D position,
     Vector3D velocity,
     Vector3D acceleration,
     double angle,
     double angVel,
     Vector3D col,
     double trans,
     double transDelta,
     double size,
     double sizeDelta,
     double ttl,
     int txtIndex
     )
 {
     this.parentEmitter = parent;
     this.position = position;
     this.velocity = velocity;
     this.acceleration = acceleration;
     this.angle = angle;
     this.angularVelocity = angVel;
     this.color = col;
     this.transparency = trans;
     this.transparencyDelta = transDelta;
     this.size = size;
     this.sizeDelta = sizeDelta;
     this.TTL = ttl;
     this.TextureIndex = txtIndex;
 }
示例#4
0
        static Particle GenerateRandomParticle(ParticleEmitter emitterParam)
        {
            MatrixCoords particlePosition = emitterParam.Position;

            int particleRowSpeed = emitterParam.RandGenerator.Next(emitterParam.MinSpeedCoord, emitterParam.MaxSpeedCoord + 1);
            int particleColSpeed = emitterParam.RandGenerator.Next(emitterParam.MinSpeedCoord, emitterParam.MaxSpeedCoord + 1);

            var particleSpeed = new MatrixCoords(particleRowSpeed, particleColSpeed);

            Particle particleGenerated = null;
            int particleTypeIndex = emitterParam.RandGenerator.Next(0, 2);

            switch (particleTypeIndex)
            {
                case 0:
                    particleGenerated = new Particle(particlePosition, particleSpeed);
                    break;
                case 1:
                    particleGenerated = new DyingParticle(particlePosition, particleSpeed, (uint) emitterParam.RandGenerator.Next(8));
                    break;
                default:
                    throw new Exception("No such particle for this particle type index!");
            }

            return particleGenerated;
        }
        static Particle GenerateRandomParticle(ParticleEmitter emitterParameter)
        {
            MatrixCoords particlePos = emitterParameter.Position;

            int particleRowSpeed = emitterParameter.RandomGenerator.Next(emitterParameter.MinSpeedCoord, emitterParameter.MaxSpeedCoord + 1);
            int particleColSpeed = emitterParameter.RandomGenerator.Next(emitterParameter.MinSpeedCoord, emitterParameter.MaxSpeedCoord + 1);

            MatrixCoords particleSpeed = new MatrixCoords(particleRowSpeed, particleColSpeed);

            Particle generated = null;

            int particleTypeIndex = emitterParameter.RandomGenerator.Next(0, 3);
            switch (particleTypeIndex)
            {
                case 0: generated = new Particle(particlePos, particleSpeed); break;
                case 1:
                    uint lifespan = (uint)emitterParameter.RandomGenerator.Next(8);
                    generated = new DyingParticle(particlePos, particleSpeed, lifespan);
                    break;
                case 2:
                    generated = new ChaoticParticle(particlePos, particleSpeed,RandomGenerator);
                    break;
                case 3:
                    generated = new ChickenParticle(particlePos, particleSpeed, RandomGenerator);
                    break;
                default:
                    throw new Exception("No such particle for this particleTypeIndex");
            }
            return generated;
        }
示例#6
0
		public void AddParticles(ParticleEmitter emitter, int count)
		{
			// Lookup what sprite sheet we're using to get the number of available frames
			Texture tex = this.RetrieveTexture();
			if (tex == null) return;
			Pixmap img = tex.BasePixmap.Res;
			if (img == null) return;
			
			// Gather data for emitting particles
			Vector3 effectPos = this.GameObj.Transform.Pos;
			float effectAngle = this.GameObj.Transform.Angle;
			float effectScale = this.GameObj.Transform.Scale;

			// Reserve memory for storing the new particles we're spawning
			if (this.particles == null) this.particles = new RawList<Particle>(count);
			int oldCount = this.particles.Count;
			this.particles.Count = this.particles.Count + count;

			// Initialize all those new particles
			Particle[] particleData = this.particles.Data;
			for (int i = oldCount; i < this.particles.Count; i++)
			{
				// Initialize the current particle.
				emitter.InitParticle(ref particleData[i]);
			}
		}
        private static void GenerateInitialData(Engine engine)
        {
            engine.AddParticle(
                new Particle(
                    new MatrixCoords(0, 8),
                    new MatrixCoords(-1, 0))
                );

            engine.AddParticle(
                new DyingParticle(
                    new MatrixCoords(20, 5),
                    new MatrixCoords(-1, 1),
                    12)
                );
            engine.AddParticle(new ChaoticParticle(
                new MatrixCoords(15,15),
                new MatrixCoords(2,2),
                RandomGenerator));
            engine.AddParticle(new ChickenParticle(new MatrixCoords(29, 0),new MatrixCoords(1,1),RandomGenerator));

            var emitterPosition = new MatrixCoords(29, 0);
            var emitterSpeed = new MatrixCoords(0, 0);
            var emitter = new ParticleEmitter(emitterPosition, emitterSpeed,
                RandomGenerator,
                5,
                2,
                GenerateRandomParticle
                );

            //engine.AddParticle(emitter);

            var attractorPosition = new MatrixCoords(10, 3);
            var attractor = new ParticleAttractor(
                attractorPosition,
                new MatrixCoords(0, 0),
                1);

            var attractorPosition2 = new MatrixCoords(10, 13);
            var attractor2 = new ParticleAttractor(
                attractorPosition2,
                new MatrixCoords(0, 0),
                3);

            engine.AddParticle(attractor);
            engine.AddParticle(attractor2);
        }
示例#8
0
        private static void GenerateInitialData(Engine engine)
        {
            engine.AddParticle(
                new Particle(
                    new MatrixCoords(0, 10),
                    new MatrixCoords(1, 1))
                );

            var emitterPosition = new MatrixCoords(29, 0);
            var emitterSpeed = new MatrixCoords(0, 0);
            var emitter = new ParticleEmitter(emitterPosition, emitterSpeed,
                rand,
                5,
                2,
                GenerateRandomParticle
                );

            engine.AddParticle(emitter);

            var emitterPosition2 = new MatrixCoords(2, 10);
            var emitterSpeed2 = new MatrixCoords(10, 5);
            var emitter2 = new ParticleEmitter(emitterPosition2, emitterSpeed2,
                rand,
                5,
                2,
                GenerateRandomParticle
                );

            engine.AddParticle(emitter2);

            var emitterPosition3 = new MatrixCoords(15, 0);
            var emitterSpeed3 = new MatrixCoords(0, 0);
            var emitter3 = new ParticleEmitter(emitterPosition3, emitterSpeed3,
                rand,
                5,
                2,
                GenerateRandomParticle
                );

            engine.AddParticle(emitter3);

            var attractorPosition = new MatrixCoords(10, 3);
            var attractor = new ParticleAttractor(
                attractorPosition,
                new MatrixCoords(0, 0),
                1);

            var attractorPosition2 = new MatrixCoords(10, 13);
            var attractor2 = new ParticleAttractor(
                attractorPosition2,
                new MatrixCoords(0, 0),
                3);

            engine.AddParticle(attractor);
            engine.AddParticle(attractor2);

            var chaoticParticle = new ChaoticParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), rand, 50, 50);
            //engine.AddParticle(chaoticParticle);

            var chickenParticle = new ChickenParticle(new MatrixCoords(15, 15), new MatrixCoords(1, 1), rand, 50, 50,
                20, 10);
            //engine.AddParticle(chickenParticle);

            var repellerParticle = new ParticleRepeller(new MatrixCoords(15, 15), new MatrixCoords(0, 0), 1, 8);
            //engine.AddParticle(repellerParticle);
        }
示例#9
0
        private static void GenerateInitialData(Engine engine)
        {
            /*engine.AddParticle(
                new Particle(
                    new MatrixCoords(0, 8),
                    new MatrixCoords(-1, 0))
                );

            engine.AddParticle(
                new DyingParticle(
                    new MatrixCoords(20, 5),
                    new MatrixCoords(-1, 1),
                    12)
                );*/

            // Test the ChaoticParticle.
            var chaoticParticle = new ChaoticParticle(
                    new MatrixCoords(20, 25),
                    new MatrixCoords(-1, 1),
                    RandomGenerator);
            engine.AddParticle(chaoticParticle);

            // Test the ChickenParticle.
            var chickenParticle = new ChickenParticle(
                new MatrixCoords(25, 15),
                new MatrixCoords(0, 1),
                RandomGenerator);
            engine.AddParticle(chickenParticle);

            // Test the ParticleRepeller.
            var particleRepeller = new ParticleRepeller(
                new MatrixCoords(10, 13),
                new MatrixCoords(0, 0),
                2, 10);

            engine.AddParticle(particleRepeller);

            var emitterPosition = new MatrixCoords(19, 15);
            var emitterSpeed = new MatrixCoords(0, 0);
            var emitter = new ParticleEmitter(emitterPosition, emitterSpeed,
                RandomGenerator,
                5,
                2,
                GenerateRandomParticle
                );

            engine.AddParticle(emitter);
            
            var attractorPosition = new MatrixCoords(10, 3);
            var attractor = new ParticleAttractor(
                attractorPosition,
                new MatrixCoords(0, 0),
                1);

            var attractorPosition2 = new MatrixCoords(10, 13);
            var attractor2 = new ParticleAttractor(
                attractorPosition2,
                new MatrixCoords(0, 0),
                3);

            // engine.AddParticle(attractor);
            // engine.AddParticle(attractor2);
        }
示例#10
0
        private static void GenerateInitialData(Engine engine)
        {
            engine.AddParticle(
               new DyingParticle(
                   new MatrixCoords(20, 5),
                   new MatrixCoords(-1, 1),
                   12)
               );

            ////Particle Emitter
            var emitterPosition = new MatrixCoords(29, 0);
            var emitterSpeed = new MatrixCoords(0, 0);
            var emitter = new ParticleEmitter(emitterPosition, emitterSpeed,
                RandomGenerator,
                5,
                2,
                GenerateRandomParticle
                );

            //engine.AddParticle(emitter);

            //// Paritcle Attractor
            var attractorPosition = new MatrixCoords(15, 20);
            var attractor = new ParticleAttractor(
                attractorPosition,
                new MatrixCoords(0, 0),
            3);
            //engine.AddParticle(attractor);

            //// IMPORTANT!
            //// Exercises 1 and 2 ->
            //// check classes: ChaoticParticle, AdvancedParticalUpdater
            var crazyPosition = new MatrixCoords(15, 12);
            var crazy = new ChaoticParticle(crazyPosition,
                new MatrixCoords(0, 0),
                RandomGenerator,
                1);

            var crazyPositiontoo = new MatrixCoords(15, 15);
            var crazytoo = new ChaoticParticle(crazyPositiontoo,
                new MatrixCoords(0, 0),
                RandomGenerator,
                1);

            var crazyPositionmore = new MatrixCoords(15, 19);
            var crazymore = new ChaoticParticle(crazyPositionmore,
                new MatrixCoords(0, 0),
                RandomGenerator,
                1);

            engine.AddParticle(crazy);
            engine.AddParticle(crazytoo);
            engine.AddParticle(crazymore);

            //// IMPORTANT!
            //// Exercises 3 and 4 ->
            //// check classes: ChickenParticle, AdvancedParticalUpdater
            var chickenPosition = new MatrixCoords(15, 12);
            var chcken = new ChickenParticle(chickenPosition,
                new MatrixCoords(0, 0),
                RandomGenerator,
                1,
                4);

            engine.AddParticle(chcken);

            //// IMPORTANT!
            //// Exercises 5 and 6 ->
            //// check classes: ParticleEmitter, AdvancedParticalUpdater
            var reppelerPosition = new MatrixCoords(18, 28);
            var reppeler = new ParticleRepeller(
                reppelerPosition,
                new MatrixCoords(0, 0),
                3);

            //engine.AddParticle(reppeler);
        }