Exemple #1
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var sizeX = particles.GetFloatValues("SizeX");
                var sizeY = particles.GetFloatValues("SizeY");

                var sizeXChangeVector = new Vector <float>(Emitter.SizeChange);
                var sizeYChangeVector = new Vector <float>(Emitter.SizeChange);

                var offset = Vector <float> .Count;

                int x;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var sizeXSlice = sizeX.Slice(x, offset);
                    var sizeYSlice = sizeY.Slice(x, offset);

                    var sizeXVector = new Vector <float>(sizeXSlice);
                    var sizeYVector = new Vector <float>(sizeYSlice);

                    var deltaXVector = sizeXChangeVector * timeSinceLastFrame;
                    var deltaYVector = sizeYChangeVector * timeSinceLastFrame;

                    (sizeXVector + deltaXVector).CopyTo(sizeXSlice);
                    (sizeYVector + deltaYVector).CopyTo(sizeYSlice);
                }

                // Remaining items
                for (; x < Program.ParticleCount; ++x)
                {
                    sizeX[x] += timeSinceLastFrame * Emitter.SizeChange;
                    sizeY[x] += timeSinceLastFrame * Emitter.SizeChange;
                }
            }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.Velocity[x] -= Emitter.Drag * particles.Velocity[x] * timeSinceLastFrame;
     }
 }
Exemple #3
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX    = particles.GetFloatValues("VelocityX");
                var velocityY    = particles.GetFloatValues("VelocityY");
                var changeVector = new Vector <float>(Emitter.SizeChange);

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var xSlice = velocityX.Slice(x, offset);
                    var ySlice = velocityY.Slice(x, offset);

                    var xVector = new Vector <float>(xSlice);
                    var yVector = new Vector <float>(ySlice);

                    var xDeltaVector = changeVector * timeSinceLastFrame;
                    var yDeltaVector = changeVector * timeSinceLastFrame;

                    (xVector + xDeltaVector).CopyTo(xSlice);
                    (yVector + yDeltaVector).CopyTo(ySlice);
                }

                for (; x < Program.ParticleCount; ++x)
                {
                    velocityX[x] += timeSinceLastFrame * Emitter.SizeChange;
                    velocityY[x] += timeSinceLastFrame * Emitter.SizeChange;
                }
            }
        public bool RemoveRandomParticle(ParticleCollection sector)
        {
            // If no sector is provided to remove from, semirandomly pick a sector from the last update.
            if (sector == null)
            {
                if (_SectorsFromLastUpdate.Count == 0)
                {
                    return(false);
                }

                var index = RNG.Next(0, _SectorsFromLastUpdate.Count);
                sector = _SectorsFromLastUpdate.GetBuffer()[index];
            }

            if (sector.Count == 0)
            {
                return(false);
            }

            var particleIndex = RNG.Next(0, sector.Count);

            sector.RemoveAt(particleIndex);

            return(true);
        }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.Size[x] += timeSinceLastFrame * new Vector2(Emitter.SizeChange, Emitter.SizeChange);
     }
 }
Exemple #6
0
        public void Manipulate(ParticleCollection particles)
        {
            if (particles == null)
                /* They do this check in C# SDL Manipulators.  Why rock the
                 * boat?
                 */
                throw new ArgumentNullException("particles");

            foreach (BaseParticle p in particles)
            {
                if (p.Static)
                    // Static particles are immobile anyway.  Nothing to do.
                    continue;

                float speedDiff = this.limit - p.Velocity.Length;

                if (speedDiff < 0)
                {
                    /* this particle is traveling too fast.  Reduce the
                     * particle's velocity to the speed limit.
                     */
                    Vector particleVelocity = p.Velocity;
                    particleVelocity.Length = this.limit;
                    p.Velocity = particleVelocity;
                }
            }
        }
Exemple #7
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var offset      = Vector <float> .Count;
                var deltaVector = new Vector <float>(timeSinceLastFrame);

                var rotationInRadians           = particles.GetFloatValues("RotationInRadians");
                var rotationalVelocityInRadians = particles.GetFloatValues("RotationalVelocityInRadians");

                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);
                int x;

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var rotationsSlice = rotationInRadians.Slice(x, offset);
                    var rotationVector = new Vector <float>(rotationsSlice);

                    var velocityVector         = new Vector <float>(rotationalVelocityInRadians.Slice(x, offset));
                    var velocitySinceLastFrame = velocityVector * deltaVector;

                    (rotationVector + velocitySinceLastFrame).CopyTo(rotationsSlice);
                }

                // Remaining values
                for (; x < Program.ParticleCount; ++x)
                {
                    rotationInRadians[x] += rotationalVelocityInRadians[x] * timeSinceLastFrame;
                }
            }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.RotationInRadians[x] += particles.RotationalVelocityInRadians[x] * timeSinceLastFrame;
     }
 }
 /// <summary>
 /// Manipulate a collection of particles with the manipulators contained in the collection.
 /// </summary>
 /// <param name="particles">The particles to manipulate.</param>
 public void Manipulate(ParticleCollection particles)
 {
     foreach (IParticleManipulator manipulator in this)
     {
         manipulator.Manipulate(particles);
     }
 }
Exemple #10
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var xSlice = velocityX.Slice(x, offset);
                    var ySlice = velocityY.Slice(x, offset);

                    var xVector = new Vector <float>(xSlice);
                    var yVector = new Vector <float>(ySlice);

                    var xDeltaVector = (xVector * Emitter.Drag) * timeSinceLastFrame;
                    var yDeltaVector = (yVector * Emitter.Drag) * timeSinceLastFrame;

                    (xVector - xDeltaVector).CopyTo(xSlice);
                    (yVector - yDeltaVector).CopyTo(ySlice);
                }

                // Remaining
                for (; x < Program.ParticleCount; x++)
                {
                    velocityX[x] -= Emitter.Drag * velocityX[x] * timeSinceLastFrame;
                    velocityY[x] -= Emitter.Drag * velocityY[x] * timeSinceLastFrame;
                }
            }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.TextureSectionIndex[x] = (byte)((particles.TimeAlive[x] / Emitter.MaxParticleLifeTime) * 10);
     }
 }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.ReferencePosition[x] += particles.Velocity[x] * timeSinceLastFrame;
         particles.Position[x].X         = particles.ReferencePosition[x].X;
         particles.Position[x].Y         = particles.ReferencePosition[x].Y + particles.Altitude[x];
     }
 }
Exemple #13
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var size = particles.GetVector2Values("Size");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    size[x] += timeSinceLastFrame * new Vector2(Emitter.SizeChange, Emitter.SizeChange);
                }
            }
Exemple #14
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocity = particles.GetVector2Values("Velocity");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    velocity[x] -= Emitter.Drag * velocity[x] * timeSinceLastFrame;
                }
            }
Exemple #15
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var textureSectionIndex = particles.GetByteValues("TextureSectionIndex");
                var timeAlive           = particles.GetFloatValues("TimeAlive");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    textureSectionIndex[x] = (byte)((timeAlive[x] / Emitter.MaxParticleLifeTime) * 10);
                }
            }
Exemple #16
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var rotationInRadians           = particles.GetFloatValues("RotationInRadians");
                var rotationalVelocityInRadians = particles.GetFloatValues("RotationalVelocityInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    rotationInRadians[x] += rotationalVelocityInRadians[x] * timeSinceLastFrame;
                }
            }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         if (particles.Velocity[x] != Vector2.Zero)
         {
             particles.RotationInRadians[x] = (float)Math.Atan2(particles.Velocity[x].Y, particles.Velocity[x].X);
         }
     }
 }
        protected void DrawSector(ParticleCollection sector)
        {
            if (sector.Count == 0)
            {
                return;
            }

            RenderArgs.SetSector(sector);
            Renderer(RenderArgs);
            RenderArgs.Enumerator.Dispose();
        }
 /// <summary>
 /// Manipulate particles by the gravity.
 /// </summary>
 /// <param name="particles">The particles to pull by the gravity.</param>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         p.Velocity += m_Velocity;
     }
 }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         var width = (((particles.InitialSize[x].X - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                      timeSinceLastFrame);
         var height = (((particles.InitialSize[x].Y - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                       timeSinceLastFrame);
         particles.Size[x].X -= width;
         particles.Size[x].Y -= height;
     }
 }
Exemple #21
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");

                var rotationInRadians = particles.GetFloatValues("RotationInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    rotationInRadians[x] = (float)Math.Atan2(velocityY[x], velocityX[x]);
                }
            }
        protected void UpdateSector(ParticleCollection sector)
        {
            if (sector.Count == 0)
            {
                return;
            }

            _SectorsFromLastUpdate.Add(sector);

            UpdateArgs.SetSector(sector);
            Updater(UpdateArgs);
            UpdateArgs.Enumerator.Dispose();
        }
Exemple #23
0
 /// <summary>
 /// Applies the friction to the given set of particles.
 /// </summary>
 /// <param name="particles">The particles to apply the friction to.</param>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         Vector vel = p.Velocity;
         vel.Length -= m_Friction;
         p.Velocity = vel;
         //p.Velocity.Length -= m_Friction;
     }
 }
Exemple #24
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocity          = particles.GetVector2Values("Velocity");
                var position          = particles.GetVector2Values("Position");
                var referencePosition = particles.GetVector2Values("ReferencePosition");
                var altitude          = particles.GetFloatValues("Altitude");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    referencePosition[x] += velocity[x] * timeSinceLastFrame;
                    position[x].X         = referencePosition[x].X;
                    position[x].Y         = referencePosition[x].Y + altitude[x];
                }
            }
Exemple #25
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocity          = particles.GetVector2Values("Velocity");
                var rotationInRadians = particles.GetFloatValues("RotationInRadians");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    if (velocity[x] != Vector2.Zero)
                    {
                        rotationInRadians[x] =
                            (float)Math.Atan2(velocity[x].Y, velocity[x].X);
                    }
                }
            }
 public void Modify(float timeSinceLastFrame, ParticleCollection particles)
 {
     for (var x = 0; x < Program.ParticleCount; x++)
     {
         particles.CurrentRed[x] -= (((particles.InitialRed[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                     timeSinceLastFrame);
         particles.CurrentGreen[x] -= (((particles.InitialGreen[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                       timeSinceLastFrame);
         particles.CurrentBlue[x] -= (((particles.InitialBlue[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                      timeSinceLastFrame);
         particles.CurrentAlpha[x] -= (((particles.InitialAlpha[x] - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                       timeSinceLastFrame);
     }
 }
Exemple #27
0
 /// <summary>
 /// Applies the friction to the given set of particles.
 /// </summary>
 /// <param name="particles">The particles to apply the friction to.</param>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         Vector vel = p.Velocity;
         vel.Length -= m_Friction;
         p.Velocity  = vel;
         //p.Velocity.Length -= m_Friction;
     }
 }
Exemple #28
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var initialSize = particles.GetVector2Values("InitialSize");
                var size        = particles.GetVector2Values("Size");

                for (var x = 0; x < Program.ParticleCount; x++)
                {
                    var width = (((initialSize[x].X - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                 timeSinceLastFrame);
                    var height = (((initialSize[x].Y - Emitter.EndValue) / Emitter.MaxParticleLifeTime) *
                                  timeSinceLastFrame);
                    size[x].X -= width;
                    size[x].Y -= height;
                }
            }
Exemple #29
0
            public void Modify(float timeSinceLastFrame, ParticleCollection particles)
            {
                var velocityX = particles.GetFloatValues("VelocityX");
                var velocityY = particles.GetFloatValues("VelocityY");
                var positionX = particles.GetFloatValues("PositionX");
                var positionY = particles.GetFloatValues("PositionY");
                var refPosX   = particles.GetFloatValues("ReferencePositionX");
                var refPosY   = particles.GetFloatValues("ReferencePositionY");
                var altitude  = particles.GetFloatValues("Altitude");

                int x;
                var offset          = Vector <float> .Count;
                var nearestMultiple = NearestMultiple(Program.ParticleCount, offset);

                for (x = 0; x < nearestMultiple; x += offset)
                {
                    var refPosXSlice = refPosX.Slice(x, offset);
                    var refPosYSlice = refPosY.Slice(x, offset);
                    var posXSlice    = positionX.Slice(x, offset);
                    var posYSlice    = positionY.Slice(x, offset);

                    var refPosXVector   = new Vector <float>(refPosXSlice);
                    var refPosYVector   = new Vector <float>(refPosYSlice);
                    var altitudeVector  = new Vector <float>(altitude.Slice(x, offset));
                    var velocityXVector = new Vector <float>(velocityX.Slice(x, offset));
                    var velocityYVector = new Vector <float>(velocityY.Slice(x, offset));

                    refPosXVector = (velocityXVector * timeSinceLastFrame) + refPosXVector;
                    refPosYVector = (velocityYVector * timeSinceLastFrame) + refPosYVector;

                    refPosXVector.CopyTo(refPosXSlice);
                    refPosYVector.CopyTo(refPosYSlice);

                    refPosXVector.CopyTo(posXSlice);
                    (refPosYVector + altitudeVector).CopyTo(posYSlice);
                }

                // Remaining
                for (; x < Program.ParticleCount; ++x)
                {
                    refPosX[x] += velocityX[x] * timeSinceLastFrame;
                    refPosY[x] += velocityY[x] * timeSinceLastFrame;

                    positionX[x] = refPosX[x];
                    positionY[x] = refPosY[x] + altitude[x];
                }
            }
Exemple #30
0
        public void Properties_Marked_As_Valid_For_Reading_Can_Be_Retrieved_As_Read_Only()
        {
            var property  = new ParticleProperty(typeof(bool), "Something");
            var allocator = new ParticleAllocator(10);

            allocator.RegisterProperty(property.Type, property.Name);

            var reservation = allocator.Reserve(5);
            var collection  = new ParticleCollection(reservation)
            {
                ValidPropertiesToRead = new HashSet <ParticleProperty>(new[] { property })
            };

            var result = collection.GetReadOnlyPropertyValues <bool>(property.Name);

            result.Length.ShouldBe(reservation.Length);
        }
Exemple #31
0
        public void Cannot_Get_Property_Not_In_Valid_Readable_Hash_Set()
        {
            var property1 = new ParticleProperty(typeof(bool), "Something");
            var property2 = new ParticleProperty(typeof(bool), "Something2");
            var allocator = new ParticleAllocator(10);

            allocator.RegisterProperty(property1.Type, property1.Name);
            allocator.RegisterProperty(property2.Type, property2.Name);

            var reservation = allocator.Reserve(5);
            var collection  = new ParticleCollection(reservation)
            {
                ValidPropertiesToSet = new HashSet <ParticleProperty>(new[] { property1 })
            };

            Assert.ThrowsAny <Exception>(() => collection.GetReadOnlyPropertyValues <bool>(property2.Name));
        }
        public static bool Set(this CompiledParticle compiled, OpenXmlCompositeElement parent, OpenXmlElement value, Type type)
        {
            if (type is null)
            {
                return(false);
            }

            if (compiled is null)
            {
                return(false);
            }

            var collection = new ParticleCollection(type, compiled, parent);

            collection.Clear();
            return(collection.Add(value));
        }
Exemple #33
0
        public Cannon(Ship owner, int barrelLength, Surface bulletSurface, float power, TimeSpan cooldown, float muzzleSpeed, int bulletLife)
        {
            this.owner = owner;
            this.bulletSurface = bulletSurface;
            this.power = power;
            this.cooldown = cooldown;
            this.muzzleSpeed = muzzleSpeed;
            this.bulletLife = bulletLife;
            this.barrelLength = barrelLength;

            this.lastFiredTime = DateTime.MinValue;

            this.bulletCollection = new ParticleCollection();

            this.fireSound = new Sound(Configuration.Ships.Cannon.FiringSoundFilename);
            this.fireSound.Volume = Configuration.SoundVolume;

            this.dryFireSound = new Sound(Configuration.Ships.Cannon.DryFireSoundFilename);
            this.dryFireSound.Volume = Configuration.SoundVolume;
        }
 public void ResetVoids(float factor)
 {
     particleCollection = new ParticleCollection(this);
     voids.Clear();
     voids.Add(new TheVoid(this)
     {
         direction = new Vector3(1, 0, 0),
         horizontalPosition = -factor * World.WorldWidth / 2
     });
     voids.Add(new TheVoid(this)
     {
         direction = new Vector3(-1, 0, 0),
         horizontalPosition = factor * World.WorldWidth / 2
     });
 }
Exemple #35
0
		public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor)
		{
			int i;
			
			// set the maximum number of particles to 1000
			m_MaxNumberOfParticles = 1000;

			Particles = new ParticleCollection(this, m_MaxNumberOfParticles); 

			// value of the boltzmann constant - we dont really care about units now...
			kb = 8.314;									
			// value of the berendsen coupling constant - set this to be controlled by the artist...
			m_BerendsenThermostatCoupling = 1.0;		
			
			m_EquilibriumTemperature = 20000;
			BerendsenThermostat = true;

			//  BerendsenThermostat=false;
			EnsembleReinitializationFlag = false;
			NumberOfParticlesChangedFlag = false;
			NumberOfParticlesIsGreaterFlag = false;

			m_RadiiScaleFactor = 1.0;
			InitialKE = 0.0;
			m_GradientScaleFactor = scaleFactor;

			step = 0;
			//NumberOfParticles = nparticles;
			m_BoxHeight = Height;
			m_BoxWidth = Width;

			m_MaxForceThreshold = 1.0e6;
			m_InitialMaxForceThreshold = m_MaxForceThreshold;

            // allocate maximum space for and initialize the velocity autocorrelation & FFT vectors
            m_FFTenabled = true;
            m_FFTofCorrelationFunction = new List<double>(new double[MAX_CORR_FTN_SIZE]);
            m_VelocityAutoCorrelationFunction = new double[MAX_CORR_FTN_SIZE];
            for (int ii = 0; ii < MAX_CORR_FTN_SIZE; ++ii)
            {
                m_VelocityAutoCorrelationFunction[ii] = 0.0;
                m_FFTofCorrelationFunction[ii] = 0.0;
            }

            for (int ii = 0; ii < FFTmatrixForMovingAverage.Count(); ++ii)
            {
                FFTmatrixForMovingAverage[ii]= new List<double>(new double[m_NumberOfFFTAverages]);
                for(int kk=0; kk < m_NumberOfFFTAverages; ++kk){
                    FFTmatrixForMovingAverage[ii][kk] = 0.0;
                }

            }

			InitialMinVel = 100.0;
			InitialMaxVel = 200.0;

			for (int ii = 0; ii < m_MaxNumberOfParticles; ++ii)
			{
				InitializeOneNewParticle();
			}

			for (int ii = nparticles; ii < m_MaxNumberOfParticles; ++ii)
			{
				Particles.Pop();
			}

			if (!EliminateParticleOverlap(Height, Width))
			{
				// adjust particle positions to eliminate overlap 
				do
				{
					// if there's too many particles to fit in the simulation box
					//NumberOfParticles -= 1;
					Particles.Pop();

					// decrement the particles till it's ok
					EliminateParticleOverlap(Height, Width);				
				}
				while (!EliminateParticleOverlap(Height, Width));
			}
			
			// create matrix to distanceMatrix & distanceMatrixLastTime
			distanceMatrix = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
			distanceMatrixLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
			distanceMatrixLastLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles);
 
			// update the particlesWithinRange matrix
			particlesWithinRange = new BoolMatrix(false, MaxNumberOfParticles, MaxNumberOfParticles); 

			// update the interparticle separation matrix
			UpdateInterParticleSeparations();						

			m_PotentialEnergy = 0.0;

			// push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be
			// easily expanded
			for (i = 0; i < FFtype.Count; ++i)
			{
				if (FFtype[i] == "SoftSpheres") { ForceFields.Add(new SoftSpheres(this)); }
			}
		}
Exemple #36
0
        public override bool Update()
        {
            this.forwardThruster.Update();
            this.reverseThruster.Update();

            // Enforce the Ship's speed limit.
            ParticleCollection particleCollection = new ParticleCollection();
            particleCollection.Add(this);
            this.speedLimiter.Manipulate(particleCollection);

            return base.Update();
        }
Exemple #37
0
 /// <summary>
 /// Manipulate particles by the gravity.
 /// </summary>
 /// <param name="particles">The particles to pull by the gravity.</param>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         p.Velocity += m_Velocity;
     }
 }
Exemple #38
0
        private void Tick(object sender, TickEventArgs e)
        {
            DateTime now = DateTime.Now;

            // Read the "game has begun" flag.
            bool gameHasBegun = this.theGameHasBegun;

            // Fill in the background.
            Video.Screen.Fill(Color.Black);
            Video.Screen.Blit(this.background);

            // Update all the particles in the universe.
            this.particleSystem.Update();

            if (gameHasBegun)
            {
                // The game has begun.

                // Spawn player 1.
                if (this.player1.Ship == null
                    || !this.player1.Ship.Alive && this.player1.Ship.RespawnTime < now)
                    SpawnShip(1);

                // Spawn player 2.
                if (this.player2.Ship == null
                    || !this.player2.Ship.Alive && this.player2.Ship.RespawnTime < now)
                    SpawnShip(2);

                if (this.player1.Ship != null && this.player2.Ship != null)
                {
                    // Perform user control (input) related updates.

                    // Player 1.
                    Bullet bullet = this.player1.ProcessUserInput();
                    if (bullet != null)
                        this.particleSystem.Particles.Add(bullet);

                    // Player 2.
                    bullet = this.player2.ProcessUserInput();
                    if (bullet != null)
                        this.particleSystem.Particles.Add(bullet);

                    // Check for collisions.
                    EnforceCollisions();
                }
            }

            // Enforce the Ship's speed limit last.
            ParticleCollection particleCollection = new ParticleCollection();
            particleCollection.Add(this.particleSystem);
            this.speedLimitManipulator.Manipulate(particleCollection);

            // Render all the particles in the universe.
            this.particleSystem.Render(Video.Screen);

            if (!gameHasBegun)
            {
                // The game hasn't actually started yet.

                // Display the title screen.
                this.mainTitle.Refresh();
            }
            else
            {
                // Display the plain InfoBar graphic.
                Video.Screen.Blit(this.infoBar, Configuration.InfoBarPosition);

                // Display the scoreCards on the InfoBar.
                this.player1.ScoreCard.Refresh(Video.Screen);
                this.player2.ScoreCard.Refresh(Video.Screen);
            }

            // Display the back-buffer onto the screen surface (double-buffering).
            Video.Screen.Update();
        }
Exemple #39
0
 /// <summary>
 /// Sets the particle collection where this emitter is to send its particles.
 /// </summary>
 /// <remarks>FXCop does not setting the collection directly in the property</remarks>
 /// <param name="particleCollection"></param>
 public void SetParticleTarget(ParticleCollection particleCollection)
 {
     m_Target = particleCollection;
 }
Exemple #40
0
 /// <summary>
 /// Creates an empty particle system with one particle manipulator.
 /// </summary>
 /// <param name="manipulator">The manipulator to use with this particle system.</param>
 public ParticleSystem(IParticleManipulator manipulator)
 {
     m_Manipulators = new ParticleManipulatorCollection();
     m_Manipulators.Add(manipulator);
     m_Particles = new ParticleCollection();
 }
Exemple #41
0
 /// <summary>
 /// Copy Constructor.
 /// </summary>
 /// <param name="system">The particle system to copy.</param>
 public ParticleSystem(ParticleSystem system)
 {
     if (system == null)
     {
         throw new ArgumentNullException("system");
     }
     m_Manipulators = new ParticleManipulatorCollection(system.Manipulators);
     m_Particles = new ParticleCollection();
     m_Particles.Add(system);
 }
Exemple #42
0
 /// <summary>
 /// Creates an empty particle system with no manipulators.
 /// </summary>
 public ParticleSystem()
 {
     m_Manipulators = new ParticleManipulatorCollection();
     m_Particles = new ParticleCollection();
 }
Exemple #43
0
        private void EnforceCollisions()
        {
            // Enforce Ship-Planet Impact.
            if (this.player1.Ship.Alive && this.player1.Ship.Collision(this.planet))
                Impact(this.player1.Ship, this.planet);
            if (this.player2.Ship.Alive && this.player2.Ship.Collision(this.planet))
                Impact(this.player2.Ship, this.planet);

            // Enforce Ship-Ship Impact.
            if (this.player1.Ship.Alive && this.player2.Ship.Alive && this.player1.Ship.Collision(this.player2.Ship))
                Impact(this.player1.Ship, this.player2.Ship);

            /* Create a shallow copy of the bullet particles to work with;
             * otherwise things go all wonky when we add particles during
             * iteration (i.e. explosions).
             */
            ParticleCollection bulletParticles = new ParticleCollection();
            foreach (BaseParticle p in this.particleSystem.Particles)
                if ((Type)p.GetType() == typeof(Bullet))
                    bulletParticles.Add(p);

            foreach (Bullet b in bulletParticles)
            {
                // Enforce Ship-Bullet impact.
                if (this.player1.Ship.Collision(b))
                    Impact(this.player1.Ship, b);
                if (this.player2.Ship.Collision(b))
                    Impact(this.player2.Ship, b);

                // Enforce Planet-Bullet impact.
                if (this.planet.Collision(b))
                    Impact(this.planet, b);
            }
        }
Exemple #44
0
 /// <summary>
 /// Creates a particle system with an already created manipulators and particles.
 /// </summary>
 /// <param name="manipulators">The manipulators to associate with this particle system.</param>
 /// <param name="particles">The particles to add to this particle system.</param>
 public ParticleSystem(ParticleManipulatorCollection manipulators, ParticleCollection particles)
 {
     m_Manipulators = manipulators;
     m_Particles = new ParticleCollection();
     m_Particles.Add(particles);
 }
Exemple #45
0
        public void Manipulate(ParticleCollection particles)
        {
            if (particles == null)
                /* They do this check in C# SDL Manipulators.  Why rock the
                 * boat?
                 */
                throw new ArgumentNullException("particles");

            // Exert gravitational force on every particle in the list.
            foreach (BaseParticle particle in particles)
            {
                if (particle.Static)
                    // Static particles are immobile.
                    continue;

                /* Create a vector from the particle's position to the gravity
                 * well.  Then get the distance and angle from it.
                 */
                Vector v = new Vector(particle.X, particle.Y, 0, position.X, position.Y, 0);

                double distance = v.Length;
                if (distance > radius)
                    // This particle is too far away to be affected.
                    continue;

                // Get the pull direction.
                int directionDeg = Convert.ToInt32(Math.Round(v.DirectionDeg));

                float force = GetForce(distance);

                // Create a vector from the force and the direction.
                v = Vector.FromDirection(directionDeg, force);

                // Add the new vector to the particle.
                particle.Velocity += v;
            }
        }
Exemple #46
0
 /// <summary>
 /// Makes sure that every particle is within the given boundary.
 /// </summary>
 /// <param name="particles">The particle collection to set inside the bounds.</param>
 /// <remarks>Particles that reach the outside the rectangle are bounced back into bounds.</remarks>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         if (p.Left < this.Left)
         {
             p.X = this.Left;
             Vector vel = p.Velocity;
             vel.X *= -1;
             p.Velocity = vel;
         }
         else if (p.Right > this.Right)
         {
             p.X = this.Right - p.Width;
             Vector vel = p.Velocity;
             vel.X *= -1;
             p.Velocity = vel;
         }
         else if (p.Top < this.Top)
         {
             p.Y = this.Top;
             Vector vel = p.Velocity;
             vel.Y *= -1;
             p.Velocity = vel;
         }
         else if (p.Bottom > this.Bottom)
         {
             p.Y = this.Bottom - p.Height;
             Vector vel = p.Velocity;
             vel.Y *= -1;
             p.Velocity = vel;
         }
     }
 }
Exemple #47
0
 /// <summary>
 /// Applies the vortex force on each particle in the vortex's radius.
 /// </summary>
 /// <param name="particles">The collection of particles to manipulate.</param>
 public void Manipulate(ParticleCollection particles)
 {
     if (particles == null)
     {
         throw new ArgumentNullException("particles");
     }
     foreach (BaseParticle p in particles)
     {
         Vector v = new Vector(p.X, p.Y, 0, m_X, m_Y, 0);
         if (m_Radius == -1f)
         {
             v.Length = m_Strength;
         }
         else
         {
             if (v.Length > m_Radius)
                 continue;
             v.Length = (1f - v.Length / m_Radius) * m_Strength;
         }
         p.Velocity += v;
     }
 }