public Particle(ParticlePropertyGroup properties, SKRect rect, Random rnd) { Position = properties.Spawn.SpawnPosition.CurrentValue switch { SpawnPosition.TopEdge => new SKPoint(rnd.RandomBetween(0, rect.Width), 0), SpawnPosition.RightEdge => new SKPoint(rect.Width, rnd.RandomBetween(0, rect.Height)), SpawnPosition.BottomEdge => new SKPoint(rnd.RandomBetween(0, rect.Width), rect.Height), SpawnPosition.LeftEdge => new SKPoint(0, rnd.RandomBetween(0, rect.Height)), SpawnPosition.Custom => new SKPoint(rect.Width * properties.Spawn.SpawnPositionPercent.CurrentValue.X, rect.Height * properties.Spawn.SpawnPositionPercent.CurrentValue.Y), _ => new SKPoint(rnd.RandomBetween(0, rect.Width), rnd.RandomBetween(0, rect.Height)), }; Velocity = new SKPoint( properties.Spawn.InitialXVelocityRange.CurrentValue.GetRandomValue(), properties.Spawn.InitialYVelocityRange.CurrentValue.GetRandomValue() ); Radius = properties.Spawn.SizeRange.CurrentValue.GetRandomValue(); Lifetime = 0; MaxLifetime = properties.Spawn.MaxLifetimeRange.CurrentValue.GetRandomValue(); }
public void Update(ParticlePropertyGroup properties, double deltaTime) { if (deltaTime < 0) { return;//TODO } Lifetime += deltaTime; Velocity = new SKPoint( Velocity.X + (float)(properties.Physics.Acceleration.CurrentValue.X * deltaTime), Velocity.Y + (float)(properties.Physics.Acceleration.CurrentValue.Y * deltaTime) ); Velocity = new SKPoint( Velocity.X * (float)Math.Pow(1 - properties.Physics.Drag.CurrentValue.X, deltaTime), Velocity.Y * (float)Math.Pow(1 - properties.Physics.Drag.CurrentValue.Y, deltaTime) ); Position = new SKPoint( Position.X + Velocity.X, Position.Y + Velocity.Y ); Radius += (float)(properties.Physics.DeltaSize.CurrentValue * deltaTime); }