public override void TickEnded()
        {
            foreach (var repeller in this.currentTickRepellers)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    int radius = (int)Math.Sqrt((repeller.Position.Col - particle.Position.Col) * (repeller.Position.Col - particle.Position.Col) + (repeller.Position.Row - particle.Position.Row) * (repeller.Position.Row - particle.Position.Row));
                    if (radius < repeller.Radius)
                    {
                        var currentParticleToRepelVector = repeller.Position - particle.Position;

                        int pToAttrRow = currentParticleToRepelVector.Row;

                        pToAttrRow = DecreaseVectorCoordToPower(repeller, pToAttrRow);
                        int pToAttrCol = currentParticleToRepelVector.Col;
                        pToAttrCol = DecreaseVectorCoordToPower(repeller, pToAttrCol);

                        //difference between repeller and attractor
                        var currentAccelaration = new MatrixCoords(-pToAttrRow, -pToAttrCol);

                        particle.Accelerate(currentAccelaration);
                    }

                }
            }

            this.currentTickParticles.Clear();
            this.currentTickRepellers.Clear();

            base.TickEnded();
        }
Пример #2
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, int freezeAfter, int freezeTime)
     : base(position, speed)
 {
     this.FreezeTime = freezeTime;
     this.FreezeAfter = freezeAfter;
     this.Freezed = false;
 }
        public override void TickEnded()
        {
            foreach (var repeller in this.repellers)
            {
                foreach (var particle in this.particles)
                {
                    double distanceFromRepellerToParticle = CalculateEuclideanDistance(repeller.Position, particle.Position);

                    if (repeller.RepellerRadius >= distanceFromRepellerToParticle)
                    {
                        var currParticleToRepellerVector = repeller.Position - particle.Position;

                        int pToAttrRow = currParticleToRepellerVector.Row;
                        pToAttrRow = DecreaseVectorCoordToPower(repeller, pToAttrRow);

                        int pToAttrCol = currParticleToRepellerVector.Col;
                        pToAttrCol = DecreaseVectorCoordToPower(repeller, pToAttrCol);

                        var currAcceleration = new MatrixCoords(-pToAttrRow, -pToAttrCol);

                        particle.Accelerate(currAcceleration);
                    }
                }
            }

            this.repellers.Clear();
            this.particles.Clear();

            base.TickEnded();
        }
        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;
        }
        public override void TickEnded()
        {
            foreach (var repeller in this.currentTickRepellers)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    var currParticleToRepellerVector = repeller.Position - particle.Position;

                    // If particle is in the radius(range), repel it.
                    // Using the same logic as "AdvancedParticleOperator". Using "Euclidean distance" formula to calculate the distance between the two particles
                    if (IsInRange(currParticleToRepellerVector, repeller))
                    {
                        int pToRepRow = currParticleToRepellerVector.Row;
                        pToRepRow = DecreaseVectorCoordToPower(repeller, pToRepRow);

                        int pToRepCol = currParticleToRepellerVector.Col;
                        pToRepCol = DecreaseVectorCoordToPower(repeller, pToRepCol);

                        var currAcceleration = new MatrixCoords(pToRepRow, pToRepCol);

                        particle.Accelerate(currAcceleration);
                    }
                }
            }

            this.currentTickParticles.Clear();
            this.currentTickRepellers.Clear();

            base.TickEnded();
        }
Пример #6
0
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, Random randomGenerator, uint maxAbsSpeedCoord)
     : base(position, speed)
 {
     this.RandomGenerator = randomGenerator;
     this.MinSpeedCoord = -(int)maxAbsSpeedCoord;
     this.MaxSpeedCoord = (int)maxAbsSpeedCoord;
 }
Пример #7
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random randGenerator)
     : base(position, speed, randGenerator)
 {
     this.ChanceToStopInPercentsCount = InitialChanceToStopInPercents;
     this.CurrentTickOfDuration = 0;
     ticksToStopForDurationCount = (uint)this.RandGenerator.Next(1, 6);
 }
Пример #8
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);
        }
Пример #9
0
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, Random randomGenerator, int crazyness)
     : base(position, speed)
 {
     this.MaximalAcceleration = crazyness;
     this.MinimalAcceleration = -crazyness;
     this.RandomGenerator = randomGenerator;
 }
Пример #10
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();
        }
Пример #11
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;
        }
        public override void TickEnded()
        {
            foreach (var repeller in this.currentTickRepellers)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    var currParticleToRepellerVector = particle.Position - repeller.Position;
                    var distance = Math.Sqrt(Math.Pow(currParticleToRepellerVector.Row, 2) +
                        Math.Pow(currParticleToRepellerVector.Col, 2));

                    if (distance <= repeller.RepellerRadius)
                    {

                        int pToAttrRow = currParticleToRepellerVector.Row;
                        pToAttrRow = DefineAcceleration(repeller, pToAttrRow);

                        int pToAttrCol = currParticleToRepellerVector.Col;
                        pToAttrCol = DefineAcceleration(repeller, pToAttrCol);

                        var currAcceleration = new MatrixCoords(pToAttrRow, pToAttrCol);

                        particle.Accelerate(currAcceleration);
                    }
                }
            }

            this.currentTickRepellers.Clear();

            base.TickEnded();
        }
Пример #13
0
        public override IEnumerable<Particle> Update()
        {
            tickCounter++;
            var newParticles = new List<Particle>();

            double totalSpeed = Math.Sqrt(this.Speed.Row * this.Speed.Row + this.Speed.Col * this.Speed.Col);
            if (tickCounter > 4 * ChickenParticle.totalChickenParticles && totalSpeed < maxSpeed)
            {
                waitCounter++;
                if (waitCounter > ticksToWait)
                {
                    ChickenParticle.totalChickenParticles++;
                    MatrixCoords initialSpeed = new MatrixCoords(0, 0);
                    var newParticle = new ChickenParticle(this.Position, initialSpeed, ChickenParticle.totalChickenParticles);
                    newParticles.Add(newParticle);

                    tickCounter = 0;
                    waitCounter = 0;
                }
            }
            else
            {
                this.Move();
            }
            
            return newParticles;
        }
Пример #14
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, int currentGeneration = 1)
     : base(position, speed)
 {
     tickCounter = 0;
     waitCounter = 0;
     this.currentGeneration = currentGeneration;
 }
        public override void TickEnded()
        {
            foreach (var attractor in this.currentTickAttractors)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    var currParticleToAttractorVector = attractor.Position - particle.Position;

                    int pToAttrRow = currParticleToAttractorVector.Row;
                    pToAttrRow = DecreaseVectorCoordToPower(attractor, pToAttrRow);

                    int pToAttrCol = currParticleToAttractorVector.Col;
                    pToAttrCol = DecreaseVectorCoordToPower(attractor, pToAttrCol);

                    var currAcceleration = new MatrixCoords(pToAttrRow, pToAttrCol);

                    particle.Accelerate(currAcceleration);
                }
            }

            this.currentTickParticles.Clear();
            this.currentTickAttractors.Clear();

            base.TickEnded();
        }
Пример #16
0
        public override IEnumerable<Particle> Update()
        {
            if (!this.currentlyStopped && this.RandomGenerator.Next(0, 101) <= this.stopFrequencyPercent)
            {
                lastKnownSpeed = this.Speed;
                this.Accelerate(new MatrixCoords(this.Speed.Row * (-1), this.Speed.Col * (-1)));
                this.currentlyStopped = true;
            }
            if (currentlyStopped)
            {
                this.currentTick++;
                if (this.currentTick == this.stopDuarationTicks)
                {
                    this.Accelerate(lastKnownSpeed);
                    this.currentTick = 0;
                    this.currentlyStopped = false;

                    var baseProduced = base.Update();

                    List<Particle> newProduced = new List<Particle>()
                    {
                        new ChickenParticle(this.Position,lastKnownSpeed,this.RandomGenerator,
                            (uint)base.DirectionChangeFrequencyRowPercent,(uint)this.DirectionChangeFrequencyColPercent,
                            (uint)this.stopFrequencyPercent,(uint)this.stopDuarationTicks)
                    };

                    newProduced.AddRange(baseProduced);

                    return newProduced;
                }
            }
            return base.Update();
        }
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed,
     Random randomGenerator, uint directionChangeFreqRowPercent, uint directionChangeFreqColPercent)
     : base(position, speed)
 {
     this.RandomGenerator = randomGenerator;
     this.directionChangeFrequencyRowPercent = (int)directionChangeFreqRowPercent;
     this.directionChangeFrequencyColPercent = (int)directionChangeFreqColPercent;
 }
 // Methods
 protected override Particle GetNewParticle(MatrixCoords position, MatrixCoords speed)
 {
     if ((this.randGen.Next() % 2) == 0)
     {
         return new DyingParticle(position, speed, this.randGen.Next(MaxLifetime));
     }
     return base.GetNewParticle(position, speed);
 }
Пример #19
0
        protected MatrixCoords GetRandomCoords()
        {
            int randomSpeedRow = this.randomGenerator.Next(-MaxSpeedPerCoordinate, MaxSpeedPerCoordinate + 1);
            int randomSpeedCol = this.randomGenerator.Next(-MaxSpeedPerCoordinate, MaxSpeedPerCoordinate + 1);

            var createdSpeed = new MatrixCoords(randomSpeedRow, randomSpeedCol);
            return createdSpeed;
        }
Пример #20
0
 /// <summary>
 /// Only constructor. Initialize all variables
 /// </summary>
 /// <param name="position">Particle position</param>
 /// <param name="speed">Particle speed</param>
 /// <param name="matrixSize">Size of the matrix(field)</param>
 /// <param name="randomGenerator">variable of type Random</param>
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, MatrixCoords matrixSize, Random randomGenerator)
     : base(position, speed)
 {
     // We need the matrix size, so we always print the chaotic particle inside the matrix
     this.MatrixSize = matrixSize;
     // Random is given in the constructor, so we can use one global Random variable, to avoid repetition of numbers
     this.randomGenerator = randomGenerator;
 }
Пример #21
0
 protected override void Move()
 {
     base.Move();
     int particleRowSpeed = this.RandomGenerator.Next(this.MinSpeedCoord, this.MaxSpeedCoord + 1);
     int particleColSpeed = this.RandomGenerator.Next(this.MinSpeedCoord, this.MaxSpeedCoord + 1);
     MatrixCoords particleSpeed = new MatrixCoords(particleRowSpeed, particleColSpeed);
     this.Accelerate(new MatrixCoords(-this.Speed.Row, -this.Speed.Col));
     this.Accelerate(particleSpeed);
 }
Пример #22
0
        private MatrixCoords GenerateRandomSpeed()
        {
            int randSpeedXCoord = this.RandGenerator.Next(-MaxSpeedChangeRange, MaxSpeedChangeRange + 1);
            int randSpeedYCoord = this.RandGenerator.Next(-MaxSpeedChangeRange, MaxSpeedChangeRange + 1);

            MatrixCoords randomSpeed = new MatrixCoords(randSpeedXCoord, randSpeedYCoord);

            return randomSpeed;
        }
Пример #23
0
 /// <summary>
 /// Only constructor. Initialize all variables
 /// </summary>
 /// <param name="position">Particle position</param>
 /// <param name="speed">Particle speed</param>
 /// <param name="matrixSize">Size of the matrix(field)</param>
 /// <param name="randomGenerator">variable of type Random</param>
 /// <param name="ticksToLayParticle">ticks delay to lay particle(egg)</param>
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, MatrixCoords matrixSize, Random randomGenerator, uint ticksToLayParticle)
     : base(position, speed, matrixSize, randomGenerator)
 {
     // Ticks to lay particle are put in the constructor, so the user can set different value
     this.ticksToLayParticle = ticksToLayParticle;
     this.currentTicksToLayParticle = ticksToLayParticle;
     // Random is given in the constructor, so we can use one global Random variable, to avoid repetition of numbers
     this.randomGenerator = randomGenerator;
 }
Пример #24
0
        // Generate random position inside the matrix
        private MatrixCoords GenerateRandomPosition()
        {
            MatrixCoords randomPosition = new MatrixCoords();

            randomPosition.Row = randomGenerator.Next(this.MatrixSize.Row);
            randomPosition.Col = randomGenerator.Next(this.MatrixSize.Col);

            return randomPosition;
        }
Пример #25
0
        public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random randomGenerator)
            : base(position, speed, randomGenerator)
        {
            this.isSpawned = true;

            BreakThicksInitialization();

            this.isMoving = true;
        }
 private bool IsParticleInRangeOfRepeller(MatrixCoords positionRepeller, MatrixCoords positionParticle, int radius)
 {
     var result = Math.Sqrt
         (
             (positionRepeller.Row - positionParticle.Row) * (positionRepeller.Row - positionParticle.Row) +
             (positionRepeller.Col - positionParticle.Col) * (positionRepeller.Col - positionParticle.Col)
         );
     return radius >= result;
 }
Пример #27
0
 public ParticleEmitter(MatrixCoords position, MatrixCoords speed, Random randGenerator, uint maxEmittedPerTickCount, uint maxAbsSpeedCoord, Func<ParticleEmitter, Particle> randomParticleGeneratorMethod)
     : base(position, speed)
 {
     this.RandGenerator = randGenerator;
     this.maxEmittedPerTickCount = maxEmittedPerTickCount;
     this.MinSpeedCoord = -(int) maxAbsSpeedCoord;
     this.MaxSpeedCoord = (int) maxAbsSpeedCoord;
     this.randomParticleGeneratorMethod = randomParticleGeneratorMethod;
 }
Пример #28
0
        public DyingParticle(MatrixCoords position, MatrixCoords speed, int lifetime)
            : base(position, speed)
        {
            if (lifetime < 0)
            {
                throw new ArgumentException("lifetime must be greater than or equal to zero");
            }

            this.lifetime = lifetime;
        }
        protected override Particle GetNewParticle(MatrixCoords position, MatrixCoords speed)
        {
            bool createDying = this.randomGenerator.Next() % 2 == 0;
            if (createDying)
            {
                return new DyingParticle(position, speed, this.randomGenerator.Next(MaxParticleLifetime));
            }

            return base.GetNewParticle(position, speed);
        }
Пример #30
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random random, 
     uint directionChangeFreqRowPercent, uint directionChangeFreqColPercent, 
     uint stopFrequencyPercent, uint stopDuarationTicks)
     : base(position,speed,random,directionChangeFreqRowPercent,directionChangeFreqColPercent)
 {
     this.stopFrequencyPercent = (int)stopFrequencyPercent;
     this.stopDuarationTicks = (int)stopDuarationTicks;
     this.currentlyStopped = false;
     this.currentTick = 0;
 }
Пример #31
0
        public override IEnumerable<Particle> Update()
        {
            // set speed to zero
            // use accelerate method because speed setter is private
            this.Accelerate(this.oppositeSpeedDirection);

            // generate new speed
            MatrixCoords speed = this.GenerateRandomSpeed();

            // set the speed to the newly generated speed
            this.Accelerate(speed);

            return base.Update();
        }
        public ParticleEmitter(MatrixCoords position, MatrixCoords speed,
                               Random randomGenerator,
                               uint maxEmittedPerTickCount, uint maxAbsSpeedCoord,
                               Func <ParticleEmitter, Particle> randomParticleGeneratorMethod) :
            base(position, speed)
        {
            this.RandomGenerator = randomGenerator;

            this.maxEmittedPerTickCount = maxEmittedPerTickCount;
            this.MinSpeedCoord          = -(int)maxAbsSpeedCoord;
            this.MaxSpeedCoord          = (int)maxAbsSpeedCoord;

            this.randomParticleGeneratorMethod = randomParticleGeneratorMethod;
        }
        private bool RepellingParticlesInRange(MatrixCoords particlePosition, MatrixCoords repellerPosition, int radius)
        {
            int repellCol        = Math.Abs(particlePosition.Col - repellerPosition.Col);
            int repellRow        = Math.Abs(particlePosition.Row - repellerPosition.Row);
            int particleDistance = (repellCol * repellCol) + (repellRow * repellRow);

            if (particleDistance <= radius)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #34
0
        private static MatrixCoords GetAccelerationFromRepellerToParticle(ParticleRepeller repeller, Particle particle)
        {
            var currParticleToAttractorVector = repeller.Position - particle.Position;

            int pToAttrRow = currParticleToAttractorVector.Row;

            pToAttrRow = DecreaseVectorCoordToPower(repeller, pToAttrRow);

            int pToAttrCol = currParticleToAttractorVector.Col;

            pToAttrCol = DecreaseVectorCoordToPower(repeller, pToAttrCol);

            var currAcceleration = new MatrixCoords(-pToAttrRow, -pToAttrCol);

            return(currAcceleration);
        }
        private static MatrixCoords GetAccelerationFromParticleToAttractor(ParticleAttractor attractor, Particle particle)
        {
            var currParticleToAttractorVector = attractor.Position - particle.Position;

            int pToAttrRow = currParticleToAttractorVector.Row;

            pToAttrRow = DecreaseVectorCoordToPower(attractor, pToAttrRow);

            int pToAttrCol = currParticleToAttractorVector.Col;

            pToAttrCol = DecreaseVectorCoordToPower(attractor, pToAttrCol);

            var currAcceleration = new MatrixCoords(pToAttrRow, pToAttrCol);

            return(currAcceleration);
        }
Пример #36
0
        public override IEnumerable <Particle> Update()
        {
            if (!HasStopped && this.RandGenerator.Next(0, 101) <= this.ChanceToStopInPercentsCount)
            {
                // save the previous chicken particle speed
                previousChickenParticleSpeed = this.Speed;

                // set the current speed to zero so that the chicken particle wont move
                this.Accelerate(this.oppositeSpeedDirection);

                this.HasStopped = true;
            }

            if (this.HasStopped)
            {
                this.CurrentTickOfDuration++;

                if (this.CurrentTickOfDuration == this.ticksToStopForDurationCount)
                {
                    this.HasStopped            = false;
                    this.CurrentTickOfDuration = 0;

                    // set the speed back to the speed, which was before the chicken particle stops
                    this.Accelerate(this.previousChickenParticleSpeed);
                }

                // create new chicken particle
                var newProducedChickenParticle = new List <Particle>()
                {
                    new ChickenParticle(this.Position, previousChickenParticleSpeed, this.RandGenerator)
                };

                //get all previous produced particles

                var baseProducedParticles = base.Update();

                // and add them to the newly produced particle
                newProducedChickenParticle.AddRange(baseProducedParticles);

                return(newProducedChickenParticle);
            }

            // if hasnt stop, we dont create new chicken particles so we simply call the base update method
            return(base.Update());
        }
Пример #37
0
        private MatrixCoords GetAccelerationFromParticleToRepeller(ParticleRepeller repeller, Particle particle)
        {
            var currParticleToRepellerVector = repeller.Position - particle.Position;
            var currAcceleration             = new MatrixCoords();


            int pToRepRow = currParticleToRepellerVector.Row;

            pToRepRow = -DecreaseVectorCoordToPower(repeller, pToRepRow);

            int pToRepCol = currParticleToRepellerVector.Col;

            pToRepCol = -DecreaseVectorCoordToPower(repeller, pToRepCol);

            currAcceleration = new MatrixCoords(pToRepRow, pToRepCol);


            return(currAcceleration);
        }
        public override void TickEnded()
        {
            foreach (var attractor in this.currentTickAttractors)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    var currParticleToAttractorVector = attractor.Position - particle.Position;

                    int pToAttrRow = currParticleToAttractorVector.Row;
                    pToAttrRow = DecreaseVectorCoordToPower(attractor, pToAttrRow);

                    int pToAttrCol = currParticleToAttractorVector.Col;
                    pToAttrCol = DecreaseVectorCoordToPower(attractor, pToAttrCol);

                    var currAcceleration = new MatrixCoords(pToAttrRow, pToAttrCol);

                    particle.Accelerate(currAcceleration);
                }
            }

            foreach (var repulsor in this.currentTickRepulsors)
            {
                foreach (var particle in this.currentTickParticles)
                {
                    if (GetDistanceBetweenPoints(repulsor, particle) <= repulsor.Range)
                    {
                        // Gets the vector between the particle position and the repulsors position
                        // and accelerates the particle in that direction

                        var currParticleToRepulsorVector = particle.Position - repulsor.Position;

                        particle.Accelerate(currParticleToRepulsorVector);
                    }
                }
            }

            this.currentTickParticles.Clear();
            this.currentTickAttractors.Clear();
            this.currentTickRepulsors.Clear();

            base.TickEnded();
        }
        public override void TickEnded()
        {
            foreach (var attractor in this.attractors)
            {
                foreach (var particle in this.particles)
                {
                    var currAcceleration = GetAccelerationFromParticleToAttractor(attractor, particle);
                    ParticleRepeller pr  = attractor as ParticleRepeller;
                    if (pr != null && Distance(pr, particle) <= pr.RepellerRadius)
                    {
                        currAcceleration = new MatrixCoords(-currAcceleration.Row, -currAcceleration.Col);
                    }

                    particle.Accelerate(currAcceleration);
                }
            }

            this.attractors.Clear();
            this.particles.Clear();
        }
Пример #40
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)
                );

            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);
        }
        public override void TickEnded()
        {
            foreach (var attractor in this.attractors)
            {
                foreach (var particle in this.particles)
                {
                    var currAcceleration = GetAccelerationFromParticleToAttractor(attractor, particle);

                    particle.Accelerate(currAcceleration);
                }
            }

            foreach (var repeller in repellers)
            {
                foreach (var particle in particles)
                {
                    int deltaCol = repeller.Position.Col - particle.Position.Col;
                    int deltaRow = repeller.Position.Row - particle.Position.Row;



                    int distance = (int)Math.Sqrt((deltaCol * deltaCol + deltaRow * deltaRow));
                    if (distance < repeller.Radius)
                    {
                        var currAcceleration = GetAccelerationFromParticleToAttractor(repeller, particle);
                        currAcceleration = new MatrixCoords(0, 0) - currAcceleration;

                        particle.Accelerate(currAcceleration);
                    }
                }
            }

            this.attractors.Clear();
            this.repellers.Clear();
            this.particles.Clear();
            base.TickEnded();
        }
        public void EnqueueForRendering(IRenderable obj)
        {
            char[,] objImage = obj.GetImage();

            int imageRows = objImage.GetLength(0);
            int imageCols = objImage.GetLength(1);

            MatrixCoords objTopLeft = obj.GetTopLeft();

            int lastRow = Math.Min(objTopLeft.Row + imageRows, this.renderContextMatrixRows);
            int lastCol = Math.Min(objTopLeft.Col + imageCols, this.renderContextMatrixCols);

            for (int row = obj.GetTopLeft().Row; row < lastRow; row++)
            {
                for (int col = obj.GetTopLeft().Col; col < lastCol; col++)
                {
                    if (row >= 0 && row < renderContextMatrixRows &&
                        col >= 0 && col < renderContextMatrixCols)
                    {
                        renderContextMatrix[row, col] = objImage[row - obj.GetTopLeft().Row, col - obj.GetTopLeft().Col];
                    }
                }
            }
        }
Пример #43
0
        public override IEnumerable <Particle> Update()
        {
            List <Particle> baseParticles = new List <Particle>(base.Update());

            if (this.movingInterval > 0)
            {
                this.movingInterval--;
            }
            else
            {
                HandleBreaks();
                if (!isSpawned)
                {
                    int rowSpeed   = this.randomGenerator.Next(-1, 2);
                    int colSpeed   = this.randomGenerator.Next(-1, 2);
                    var speed      = new MatrixCoords(rowSpeed, colSpeed);
                    var layProduct = new ChickenParticle(this.Position, speed, this.randomGenerator);
                    baseParticles.Add(layProduct);
                    isSpawned = !isSpawned;
                }
            }

            return(baseParticles);
        }
Пример #44
0
        private static void GenerateInitialData(Engine engine)
        {
            engine.AddParticle(
                new Particle(
                    new MatrixCoords(10, 10),
                    new MatrixCoords(0, 0))
                );

            engine.AddParticle(
                new DyingParticle(
                    new MatrixCoords(20, 30),
                    new MatrixCoords(-1, 1), 8)
                );

            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(15, 15);
            var attractor         = new ParticleAttractor(attractorPosition, new MatrixCoords(0, 0), 1);

            engine.AddParticle(attractor);

            var repellerPosition = new MatrixCoords(15, 25);
            var repeller         = new ParticleRepeller(repellerPosition, new MatrixCoords(0, 0), 3, 10);

            engine.AddParticle(repeller);

            //engine.AddParticle(
            //    new ChickenParticle(
            //        new MatrixCoords(10, 10),
            //        new MatrixCoords(0, 0), RandomGenerator, 2)
            //    );
        }
        public override void TickEnded()
        {
            foreach (var repeller in currentTickRepellers)
            {
                foreach (var particle in currentTickParticles)
                {
                    bool repelling = RepellingParticlesInRange(particle.Position, repeller.Position, repeller.RepellRadius);

                    if (repelling == true)
                    {
                        int reverseRow = particle.Speed.Row * 2;
                        int reverseCol = particle.Speed.Col * 2;

                        var currAcceleration = new MatrixCoords(-reverseRow, -reverseCol);

                        particle.Accelerate(currAcceleration);
                    }
                }
            }
            this.currentTickParticles.Clear();
            this.currentTickRepellers.Clear();

            base.TickEnded();
        }
Пример #46
0
 public ParticleRepeller(MatrixCoords position, MatrixCoords speed, int repellerPower, double radius)
     : base(position, speed)
 {
     this.RepellerPower  = repellerPower;
     this.RepellerRadius = radius;
 }
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, int maxTolerance, Random randomGenerator)
     : base(position, speed)
 {
     this.MaxTolerance = maxTolerance;
     this.rand         = randomGenerator;
 }
Пример #48
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random randGenerator) : base(position, speed, randGenerator)
 {
     this.ChanceToStopInPercentsCount = InitialChanceToStopInPercents;
     this.CurrentTickOfDuration       = 0;
     ticksToStopForDurationCount      = (uint)this.RandGenerator.Next(1, 6);
 }
Пример #49
0
 public ParticleAtractor(MatrixCoords position, MatrixCoords speed, int attraction)
     : base(position, speed)
 {
     this.Attraction = attraction;
 }
Пример #50
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);
        }
 public ParticleAttractor(MatrixCoords position, MatrixCoords speed, int attractionPower)
     : base(position, speed)
 {
     this.Power = attractionPower;
 }
Пример #52
0
 public VariousLifeTimeParticleEmiter(MatrixCoords position, MatrixCoords speed, Random randomGenerator) : base(position, speed, randomGenerator)
 {
 }
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random randomGenerator)
     : base(position, speed, randomGenerator)
 {
 }
Пример #54
0
 public ChickenParticle(MatrixCoords position, MatrixCoords speed, Random randGenerator, uint chanceToStopInPercentsCount)
     : this(position, speed, randGenerator)
 {
     this.ChanceToStopInPercentsCount = chanceToStopInPercentsCount;
 }
Пример #55
0
 protected virtual void Move()
 {
     this.Position += this.Speed;
 }
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, Random rnd, uint maxSpeed)
     : base(position, speed)
 {
     this.Rnd      = rnd;
     this.MaxSpeed = maxSpeed;
 }
Пример #57
0
 public Particle(MatrixCoords position, MatrixCoords speed)
 {
     this.Position = position;
     this.Speed    = speed;
 }
Пример #58
0
 public void Accelerate(MatrixCoords acceleration)
 {
     this.Speed += acceleration;
 }
 public ChaoticParticle(MatrixCoords position, MatrixCoords speed, Random randomGenerator)
     : base(position, speed)
 {
     this.randomSpeedGEnerator = randomGenerator;
 }
Пример #60
0
 public DyingParticle(MatrixCoords position, MatrixCoords speed, uint lifespan = uint.MaxValue)
     : base(position, speed)
 {
     this.lifespan = lifespan;
 }