public void InitializeParticlePropertiesRespawn(DefaultSprite3DBillboardParticle cParticle) { //----------------------------------------------------------- // TODO: Initialize all of the Particle's properties here. // If you plan on simply using the default InitializeParticleUsingInitialProperties // Particle Initialization Function (see the LoadParticleSystem() function above), // then you may delete this function all together. //----------------------------------------------------------- // Set the Particle's Lifetime (how long it should exist for) cParticle.Lifetime = 1.0f; // Set the Particle's initial Position to be wherever the Emitter is cParticle.Position = Vector3.Zero; cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation); // Set the Particle's Velocity cParticle.Velocity = DPSFHelper.PointOnSphere(RandomNumber.Between(0, MathHelper.TwoPi), RandomNumber.Between(0, MathHelper.TwoPi), radius); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); cParticle.Position += Emitter.PositionData.Position; // Give the Particle a random Size // Since we have Size Lerp enabled we must also set the Start and End Size cParticle.Width = cParticle.StartWidth = cParticle.EndWidth = cParticle.EndHeight = cParticle.Height = cParticle.StartHeight = size; // Give the Particle a random Color // Since we have Color Lerp enabled we must also set the Start and End Color cParticle.Color = cParticle.StartColor = Color.White; cParticle.EndColor = Color.Blue; }
public override void InitializeParticleProperties(DefaultSpriteParticle cParticle) { cParticle.Lifetime = DPSFHelper.RandomNumberBetween(.5f, 1); cParticle.Position = Emitter.PositionData.Position; float randomVelocity = DPSFHelper.RandomNumberBetween(-200, 200); currentRotation += (float)Math.PI / 20; Vector2 rotatedRandomVector = TankGame.rotateVector(new Vector2(randomVelocity, randomVelocity), currentRotation); cParticle.Velocity = new Vector3(rotatedRandomVector.X, rotatedRandomVector.Y, 0); cParticle.Width = DPSFHelper.RandomNumberBetween(2, 6); cParticle.Height = DPSFHelper.RandomNumberBetween(2, 12); cParticle.Rotation = currentRotation; //Vector3 sVelocityMin = new Vector3(-100, 25, -100); //Vector3 sVelocityMax = new Vector3(100, 50, 100); //cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); //cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); cParticle.StartColor = startColor; cParticle.EndColor = endColor; }
/// <summary> /// Function to Initialize a new Particle's properties /// </summary> /// <param name="cParticle">The Particle to be Initialized</param> public void InitializeParticleProperties(SpriteParticleSystemTemplateParticle cParticle) { //----------------------------------------------------------- // TODO: Initialize all of the Particle's properties here. // In addition to initializing the Particle properties you added, you // must also initialize the Lifetime property that is inherited from DPSFParticle //----------------------------------------------------------- // Set the Particle's Lifetime (how long it should exist for) cParticle.Lifetime = 2.0f; // Set the Particle's initial Position to be wherever the Emitter is cParticle.Position = Emitter.PositionData.Position; // Set the Particle's Velocity Vector3 sVelocityMin = new Vector3(-200, -200, 0); Vector3 sVelocityMax = new Vector3(200, -400, 0); cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); // Set the Particle's Width and Height cParticle.Width = RandomNumber.Next((int)mfSizeMin, (int)mfSizeMax); cParticle.Height = RandomNumber.Next((int)mfSizeMin, (int)mfSizeMax); }
/// <summary> /// Example of how to create a Particle Initialization Function /// </summary> /// <param name="cParticle">The Particle to be Initialized</param> public void InitializeParticleProperties(DefaultQuadParticle cParticle) { //----------------------------------------------------------- // TODO: Initialize all of the Particle's properties here. // If you plan on simply using the default InitializeParticleUsingInitialProperties // Particle Initialization Function (see the LoadParticleSystem() function above), // then you may delete this function all together. //----------------------------------------------------------- // Set the Particle's Lifetime (how long it should exist for) cParticle.Lifetime = 2.0f; // Set the Particle's initial Position to be wherever the Emitter is cParticle.Position = Emitter.PositionData.Position; // Set the Particle's Velocity Vector3 sVelocityMin = new Vector3(-50, 50, -50); Vector3 sVelocityMax = new Vector3(50, 100, 50); cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); // Give the Particle a random Size // Since we have Size Lerp enabled we must also set the Start and End Size cParticle.Width = cParticle.StartWidth = cParticle.EndWidth = cParticle.Height = cParticle.StartHeight = cParticle.EndHeight = RandomNumber.Next(10, 50); // Give the Particle a random Color // Since we have Color Lerp enabled we must also set the Start and End Color cParticle.Color = cParticle.StartColor = cParticle.EndColor = DPSFHelper.RandomColor(); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.3f, 0.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.Black; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(1, 50); particle.ExternalForce = new Vector3(0, 80, 0); // We want the smoke to rise particle.Size = particle.StartSize = 1; // Have the particles start small and grow particle.EndSize = ExplosionParticleSize; // Give the particle a random initial orientation and random rotation velocity (only need to Roll the particle since it will always face the camera) particle.Rotation = RandomNumber.Between(0, MathHelper.TwoPi); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 4)) { default: case 0: textureCoordinates = _flameSmoke1TextureCoordinates; break; case 1: textureCoordinates = _flameSmoke2TextureCoordinates; break; case 2: textureCoordinates = _flameSmoke3TextureCoordinates; break; case 3: textureCoordinates = _flameSmoke4TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); }
public override void AutoInitialize(GraphicsDevice cGraphicsDevice, ContentManager cContentManager, SpriteBatch cSpriteBatch) { InitializeSpriteParticleSystem(cGraphicsDevice, cContentManager, (int)DPSFHelper.RandomNumberBetween(10, 400), (int)DPSFHelper.RandomNumberBetween(10, 400), "Textures/Pixel", cSpriteBatch); Name = "Confetti"; LoadParticleSystem(); }
public Spark(TankGame cGame, Vector2 position, int maxParticles, float lifeTime) : base(cGame) { offsetX = DPSFHelper.RandomNumberBetween(-20, 20); offsetY = DPSFHelper.RandomNumberBetween(-20, 20); this.position = new Vector3(position.X + offsetX, position.Y + offsetY, 0); this.maxParticles = maxParticles; this.lifeTime = lifeTime; }
/// <summary> /// Function to setup the Render Properties (i.e. BlendState, DepthStencilState, RasterizerState, and SamplerState) /// which will be applied to the Graphics Device before drawing the Particle System's Particles. /// <para>This function is called when initializing the particle system.</para> /// </summary> protected override void InitializeRenderProperties() { //----------------------------------------------------------- // TODO: Set any render properties required before drawing //----------------------------------------------------------- // We use the Alpha Test Effect by default for 3D Sprites this.Effect = new AlphaTestEffect(this.GraphicsDevice); RenderProperties.RasterizerState = DPSFHelper.CloneRasterizerState(RasterizerState.CullNone); }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.5f, 1.0f); particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position + new Vector3(RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25), RandomNumber.Next(-25, 25)); particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(30, 50); particle.ExternalForce = new Vector3(0, 20, 0); particle.Size = ExplosionParticleSize; particle.SetTextureCoordinates(_roundSparkTextureCoordinates); }
public override void InitializeParticleProperties(DefaultSpriteParticle cParticle) { cParticle.Lifetime = DPSFHelper.RandomNumberBetween(1, 2); cParticle.Position = Emitter.PositionData.Position; cParticle.StartSize = 40; cParticle.EndSize = 10; cParticle.StartColor = Color.Yellow; cParticle.EndColor = Color.DarkRed; }
/// <summary> /// Initialize the properties of a particle. /// </summary> /// <param name="particle">Reference to the particle to be initialized.</param> public void InitializeParticleProperties(DefaultTexturedQuadParticle particle) { // Set the Particle's Lifetime (how long it should exist for) and initial Position particle.Lifetime = 5; particle.Position = Emitter.PositionData.Position; // Give the Particle a random velocity direction to start with particle.Velocity = DPSFHelper.RandomNormalizedVector() * 0.5f; particle.Size = 0.2f; particle.Color = Color.Red; }
public void InitializeParticleExplosion(DefaultTextureQuadTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.5f, 1.0f); particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position; particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(175, 225); particle.Right = -particle.Velocity; particle.Width = ExplosionParticleSize; particle.Height = ExplosionParticleSize * _textureAspectRatio; // Set the spark particle's texture coordinates particle.SetTextureCoordinates(_sparkTextureCoordinates, Texture.Width, Texture.Height); }
//=========================================================== // Particle Update Functions //=========================================================== //----------------------------------------------------------- // TODO: Place your Particle Update functions here, using the // same function prototype as below (i.e. public void FunctionName(DPSFParticle, float)) //----------------------------------------------------------- /// <summary> /// Example of how to create a Particle Event Function /// </summary> /// <param name="cParticle">The Particle to update</param> /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param> protected void UpdateParticlePositionBySphereLerp(DefaultSpriteParticle cParticle, float fElapsedTimeInSeconds) { cParticle.Position = DPSFHelper.PointOnSphere(RandomNumber.Between(0, MathHelper.TwoPi), RandomNumber.Between(0, MathHelper.TwoPi), cParticle.NormalizedElapsedTime * radius); cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation); // Adjust the Particle's Velocity direction according to the Emitter's Orientation //cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); cParticle.Position += Emitter.PositionData.Position; // Place code to update the Particle here // Example: cParticle.Position += cParticle.Velocity * fElapsedTimeInSeconds; }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFireSmokeColor(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have particle be the specified color for the first part of its lifetime float firstPartOfLifetime = 0.2f; if (particle.NormalizedElapsedTime < firstPartOfLifetime) { particle.Color = particle.StartColor; } // Then start fading it to black to look like smoke else { float lerpAmount = (particle.NormalizedElapsedTime - firstPartOfLifetime) * (1.0f / (1.0f - firstPartOfLifetime)); particle.Color = DPSFHelper.LerpColor(particle.StartColor, particle.EndColor, lerpAmount); } }
public override void LoadParticleSystem() { ParticleInitializationFunction = InitializeParticleUsingInitialProperties; InitialProperties.LifetimeMin = 1; InitialProperties.LifetimeMax = 20; InitialProperties.PositionMin = Vector3.Zero; InitialProperties.PositionMax = Vector3.Zero; InitialProperties.VelocityMin = new Vector3(-20, 20, 0); InitialProperties.VelocityMax = new Vector3(20, 100, 0); InitialProperties.RotationMin = 0.0f; InitialProperties.RotationMax = 0.0f; InitialProperties.RotationalVelocityMin = -MathHelper.Pi; InitialProperties.RotationalVelocityMax = MathHelper.Pi; InitialProperties.StartWidthMin = 5; InitialProperties.StartWidthMax = 20; InitialProperties.StartHeightMin = 5; InitialProperties.StartHeightMax = 20; InitialProperties.EndWidthMin = 0; InitialProperties.EndWidthMax = 10; InitialProperties.EndHeightMin = 0; InitialProperties.EndHeightMax = 10; InitialProperties.StartColorMin = Color.Black; InitialProperties.StartColorMax = Color.White; InitialProperties.EndColorMin = Color.Black; InitialProperties.EndColorMax = Color.White; ParticleEvents.RemoveAllEvents(); ParticleSystemEvents.RemoveAllEvents(); ParticleEvents.AddEveryTimeEvent(UpdateParticlePositionUsingVelocity); ParticleEvents.AddEveryTimeEvent(UpdateParticleRotationUsingRotationalVelocity); ParticleEvents.AddEveryTimeEvent(UpdateParticleWidthAndHeightUsingLerp); ParticleEvents.AddEveryTimeEvent(UpdateParticleColorUsingLerp); ParticleEvents.AddEveryTimeEvent(UpdateParticleTransparencyToFadeOutUsingLerp, 100); ParticleSystemEvents.LifetimeData.EndOfLifeOption = CParticleSystemEvents.EParticleSystemEndOfLifeOptions.Destroy; ParticleSystemEvents.LifetimeData.Lifetime = 20; ParticleSystemEvents.AddTimedEvent(0.0f, UpdateParticleSystemEmitParticlesAutomaticallyOn); ParticleSystemEvents.AddTimedEvent(.6f, UpdateParticleSystemEmitParticlesAutomaticallyOff); Emitter.ParticlesPerSecond = DPSFHelper.RandomNumberBetween(100, 2000); Emitter.PositionData.Position = position; }
//=========================================================== // Other Particle System Functions //=========================================================== //----------------------------------------------------------- // TODO: Place any other functions here //----------------------------------------------------------- private void addIndiParticle(bool frontRing) { BeatIndicatorParticleSystemParticle cParticle = new BeatIndicatorParticleSystemParticle(); cParticle.Lifetime = 0; //cParticle.ElapsedTime = elapsedAmount; Quaternion cBackup = Emitter.OrientationData.Orientation; Emitter.OrientationData.Orientation = Quaternion.Identity; //InitializeParticleUsingInitialProperties(cParticle); Emitter.OrientationData.Orientation = cBackup; //cParticle.Position = DPSFHelper.PointOnSphere(MathHelper.PiOver2, RandomNumber.Between(0, MathHelper.TwoPi), startingRadius); if (frontRing) { cParticle.Position = new Vector3(0, 0, 0.5f); } else { cParticle.Position = new Vector3(0, 0, -0.5f); } cParticle.Position += Emitter.PositionData.Position; // Set the Particle's initial Position to be wherever the Emitter is //cParticle.Position = Emitter.PositionData.Position; // Set the Particle's Velocity Vector3 sVelocityMin = new Vector3(0, 0, 0); Vector3 sVelocityMax = new Vector3(0, 0, 0); cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); // Give the Particle a random Size cParticle.Width = startingRadius; cParticle.Height = startingRadius; // Give the Particle a random Color cParticle.Color = Color;// DPSFHelper.RandomColor(); AddParticle(cParticle); }
public void InitializeParticleSnow(DefaultTexturedQuadParticle cParticle) { // Position the Snow within 500 units of the emitter Vector3 sPosition = Emitter.PositionData.Position; sPosition.Y = 200; sPosition.X += RandomNumber.Next(-500, 500); sPosition.Z += RandomNumber.Next(-500, 500); cParticle.Lifetime = 0.0f; cParticle.Position = sPosition; cParticle.Size = RandomNumber.Next(2, 5); cParticle.Color = DPSFHelper.LerpColor(new Color(255, 255, 255, 50), new Color(255, 255, 255, 255), RandomNumber.NextFloat()); cParticle.Orientation = Orientation3D.Rotate(Matrix.CreateRotationZ(RandomNumber.Between(0, MathHelper.TwoPi)), cParticle.Orientation); cParticle.Velocity = new Vector3(RandomNumber.Next(-10, 3), RandomNumber.Next(-15, -5), RandomNumber.Next(-10, 10)); cParticle.Acceleration = Vector3.Zero; cParticle.RotationalVelocity.Z = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); }
public override void InitializeParticleProperties(DefaultSpriteParticle cParticle) { cParticle.Lifetime = DPSFHelper.RandomNumberBetween(.1f, lifeTime / 2); cParticle.Position = Emitter.PositionData.Position; currentRotation += (float)Math.PI / 10; Vector2 rotatedRandomVector = TankGame.rotateVector(originalVector, currentRotation); cParticle.Velocity = new Vector3(rotatedRandomVector.X * 60, rotatedRandomVector.Y * 60, 0); cParticle.Size = DPSFHelper.RandomNumberBetween(1, 4); cParticle.Rotation = currentRotation; cParticle.StartColor = Color.Yellow; cParticle.EndColor = Color.Red; cParticle.Friction = DPSFHelper.RandomNumberBetween(50, 200); }
public void InitializeParticleRotators(DPSFParticle Particle) { SpriteParticle cParticle = (SpriteParticle)Particle; cParticle.Lifetime = 0; cParticle.Color = DPSFHelper.RandomColor(); cParticle.Width = cParticle.Height = 30; int iWidthBetweenParticles = miScreenWidth / miColumns; int iHeightBetweenParticles = miScreenHeight / miRows; int iRow = NumberOfActiveParticles / miColumns; int iColumn = NumberOfActiveParticles % miColumns; float fX = (iWidthBetweenParticles / 4) + (iColumn * iWidthBetweenParticles) - (cParticle.Width / 2); float fY = (iHeightBetweenParticles / 4) + (iRow * iHeightBetweenParticles) - (cParticle.Height / 2); cParticle.Position = new Vector3(fX, fY, 0); cParticle.sPivotPoint = new Vector2(fX + (iWidthBetweenParticles / 4), fY + (iHeightBetweenParticles / 4)); cParticle.RotationalVelocity = RandomNumber.Between(-MathHelper.TwoPi, MathHelper.TwoPi); }
public override void LoadParticleSystem() { ParticleInitializationFunction = InitializeParticleProperties; ParticleEvents.RemoveAllEvents(); ParticleSystemEvents.RemoveAllEvents(); ParticleEvents.AddEveryTimeEvent(UpdateParticlePositionUsingVelocity); ParticleEvents.AddEveryTimeEvent(UpdateParticleRotationUsingRotationalVelocity); ParticleEvents.AddEveryTimeEvent(UpdateParticleColorUsingLerp); ParticleEvents.AddEveryTimeEvent(UpdateParticleTransparencyToFadeOutUsingLerp, 100); ParticleSystemEvents.LifetimeData.EndOfLifeOption = CParticleSystemEvents.EParticleSystemEndOfLifeOptions.Destroy; ParticleSystemEvents.LifetimeData.Lifetime = DPSFHelper.RandomNumberBetween(0.5f, 2.0f); ParticleSystemEvents.AddTimedEvent(0.0f, UpdateParticleSystemEmitParticlesAutomaticallyOn); ParticleSystemEvents.AddTimedEvent(.2f, UpdateParticleSystemEmitParticlesAutomaticallyOff); Emitter.ParticlesPerSecond = DPSFHelper.RandomNumberBetween(100, 2000); Emitter.PositionData.Position = position; }
/// <summary> /// Function to Initialize a new Particle's properties /// </summary> /// <param name="cParticle">The Particle to be Initialized</param> public void InitializeParticleProperties(BeatIndicatorParticleSystemParticle cParticle) { //----------------------------------------------------------- // TODO: Initialize all of the Particle's properties here. // In addition to initializing the Particle properties you added, you // must also initialize the Lifetime property that is inherited from DPSFParticle //----------------------------------------------------------- cParticle.Lifetime = duration; //cParticle.ElapsedTime = elapsedAmount; Quaternion cBackup = Emitter.OrientationData.Orientation; Emitter.OrientationData.Orientation = Quaternion.Identity; //InitializeParticleUsingInitialProperties(cParticle); Emitter.OrientationData.Orientation = cBackup; //cParticle.Position = DPSFHelper.PointOnSphere(MathHelper.PiOver2, RandomNumber.Between(0, MathHelper.TwoPi), startingRadius); cParticle.Position = Vector3.Transform(cParticle.Position, Emitter.OrientationData.Orientation); //cParticle.Position += Emitter.PositionData.Position; // Set the Particle's initial Position to be wherever the Emitter is //cParticle.Position = Emitter.PositionData.Position; // Set the Particle's Velocity Vector3 sVelocityMin = new Vector3(-1, -1, -1); Vector3 sVelocityMax = new Vector3(1, 1, 1); cParticle.Velocity = DPSFHelper.RandomVectorBetweenTwoVectors(sVelocityMin, sVelocityMax); // Adjust the Particle's Velocity direction according to the Emitter's Orientation cParticle.Velocity = Vector3.Transform(cParticle.Velocity, Emitter.OrientationData.Orientation); // Give the Particle a random Size cParticle.Width = startingRadius; cParticle.Height = startingRadius; // Give the Particle a random Color cParticle.Color = Color;// DPSFHelper.RandomColor(); }
public Fireworks(TankGame cGame, Vector2 position) : base(cGame) { this.position = new Vector3(position.X, position.Y, 0); switch ((int)DPSFHelper.RandomNumberBetween(0, 3)) { case 0: startColor = Color.Yellow; endColor = Color.DarkRed; break; case 1: startColor = Color.LightCyan; endColor = Color.Green; break; case 2: startColor = Color.LightBlue; endColor = Color.DarkBlue; break; } }
public void InitializeParticleExplosion(DefaultTextureQuadTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(0.3f, 0.5f); particle.Color = ExplosionColor; particle.Position = Emitter.PositionData.Position; particle.Velocity = DPSFHelper.RandomNormalizedVector() * RandomNumber.Next(100, 150); particle.Right = -particle.Velocity; // Specify the particle's width-to-height ratio as 8:1 so it looks better particle.Width = 8; particle.Height = 1; // Calculate and set what the particle's EndWidth and EndHeight should be (2 times the start size) particle.ScaleToWidth(ExplosionParticleSize * 2); particle.EndWidth = particle.Width; particle.EndHeight = particle.Height; // Calculate and set what the particle's StartWidth and StartHeight should be particle.ScaleToWidth(ExplosionParticleSize); particle.StartWidth = particle.Width; particle.StartHeight = particle.Height; // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 3)) { default: case 0: textureCoordinates = _smokeTrail1TextureCoordinates; break; case 1: textureCoordinates = _smokeTrail2TextureCoordinates; break; case 2: textureCoordinates = _smokeTrail3TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates, Texture.Width, Texture.Height); }
public void InitializeParticleAttraction(DPSFParticle Particle) { SpriteParticle cParticle = (SpriteParticle)Particle; cParticle.Lifetime = 0; cParticle.Width = cParticle.Height = 50; cParticle.Position = new Vector3(RandomNumber.Next(-miScreenWidth / 2, miScreenWidth / 2), RandomNumber.Next(-miScreenHeight / 2, miScreenHeight / 2), 0); cParticle.Color = DPSFHelper.RandomColor(); cParticle.ExternalForce = new Vector3(0, mfGravity, 0); cParticle.Friction = mfGravity; // If this is the Attractor Particle (i.e. the first Particle added) if (NumberOfActiveParticles == 0) { // Make the Attractor Particle larger than the rest cParticle.Width = cParticle.Height = 150; // Place the Attractor in the middle of the screen cParticle.Position = new Vector3(miScreenWidth / 2, miScreenHeight / 2, 0); // Make the Attractor White cParticle.Color = Color.White; } }
public void InitializeParticleExplosion(DefaultSprite3DBillboardTextureCoordinatesParticle particle) { particle.Lifetime = RandomNumber.Between(1.2f, 1.7f); particle.Color = particle.StartColor = ExplosionColor; particle.EndColor = Color.DarkGray; particle.Position = Emitter.PositionData.Position; particle.ExternalForce = new Vector3(0, -80, 0); particle.RotationalVelocity = RandomNumber.Between(-MathHelper.PiOver2, MathHelper.PiOver2); particle.Velocity = DPSFHelper.RandomNormalizedVector(); // Calculate the direction the particle will travel in // We want the debris to travel upwards more often than downward, so if it's travelling downward switch it to travel upward 50% of the time if (particle.Velocity.Y < 0 && RandomNumber.Next(0, 2) == 0) { particle.Velocity.Y *= -1; } // Fire some particles towards the camera (but not directly at it) for a more dramatic effect if (RandomNumber.Between(0, 5) == 0) { // Calculate a point somewhere around the camera int distance = 10; Vector3 somewhereAroundTheCamera = new Vector3(CameraPosition.X + RandomNumber.Next(-distance, distance), CameraPosition.Y + RandomNumber.Next(-distance, distance), CameraPosition.Z + RandomNumber.Next(-distance, distance)); // Direct the Particle towards the spot around the camera particle.Velocity = somewhereAroundTheCamera - particle.Position; particle.Velocity.Normalize(); } // Set the Particle's Speed particle.Velocity *= RandomNumber.Next(100, 150); // Randomly pick which texture coordinates to use for this particle Rectangle textureCoordinates; switch (RandomNumber.Next(0, 9)) { default: case 0: textureCoordinates = _debris1TextureCoordinates; break; case 1: textureCoordinates = _debris2TextureCoordinates; break; case 2: textureCoordinates = _debris3TextureCoordinates; break; case 3: textureCoordinates = _debris4TextureCoordinates; break; case 4: textureCoordinates = _debris5TextureCoordinates; break; case 5: textureCoordinates = _debris6TextureCoordinates; break; case 6: textureCoordinates = _debris7TextureCoordinates; break; case 7: textureCoordinates = _debris8TextureCoordinates; break; case 8: textureCoordinates = _debris9TextureCoordinates; break; } particle.SetTextureCoordinates(textureCoordinates); // Set the Width to Height ratio so the image isn't skewed when we scale it particle.Width = textureCoordinates.Width; particle.Height = textureCoordinates.Height; // Set the particle to the specified size, give or take 25% particle.ScaleToWidth(ExplosionParticleSize * RandomNumber.Between(0.75f, 1.25f)); }
/// <summary> /// Change the color of the explosion to a random color. /// </summary> public void ChangeExplosionColor() { ExplosionColor = DPSFHelper.RandomColor(); }
//=========================================================== // Particle Update Functions //=========================================================== protected void UpdateParticleFlashSize(DefaultSprite3DBillboardTextureCoordinatesParticle particle, float elapsedTimeInSeconds) { // Have the particle reach its full size when it reaches half its lifetime, and then shrink back to nothing particle.Size = MathHelper.Lerp(particle.StartSize, particle.EndSize, DPSFHelper.InterpolationAmountForEqualLerpInAndLerpOut(particle.NormalizedElapsedTime)); }