Esempio n. 1
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;
        }
        private static void GenerateParticle(Engine engine)
        {
            engine.AddParticle(new Particle(
                new MatrixCoords(15, 0),
                new MatrixCoords(0, 1)
                ));

            engine.AddParticle(new DyingParticle(
                new MatrixCoords(0, 15),
                new MatrixCoords(1, 0),
                8
                ));
            var emitterPosition = new MatrixCoords(15, 15);

            var emitterSpeed = new MatrixCoords(0, 0);

            var emitter = new ParticleEmiter(emitterPosition, emitterSpeed, RandomGenerator, 5, 2, (emitterParameter) =>
            {
                MatrixCoords particlePos = emitterParameter.Position;

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

                MatrixCoords particleSpeed = new MatrixCoords(particleRowSpeed,particleColSpeed);

                Particle generated = null;

                int particleTypeIndex = emitterParameter.Generator.Next(0, 2);
                switch (particleTypeIndex)
                {
                    case 0: generated = new Particle(particlePos, particleSpeed); break;
                    case 1:
                        uint lifespan = (uint)emitterParameter.Generator.Next(8);
                        generated = new DyingParticle(particlePos,particleSpeed,lifespan);
                        break;
                    default:
                        throw new ArgumentException("Invalid Type");
                }
                return generated;
            }
            );
            engine.AddParticle(emitter);
        }
Esempio n. 3
0
        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, 2);
            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;
                default:
                    throw new Exception("No such particle for this particleTypeIndex");
            }
            return generated;
        }