void AddFirework(double x, double y) { for (int i = 0; i < FIREWORK_NUM; i++) { double size = SIZE_MIN + (SIZE_MAX - SIZE_MIN) * Defaults.RandomGenerator.NextDouble(); byte red = (byte)(128 + Defaults.RandomGenerator.Next(128)); byte green; byte blue; if (_shadeOfWhite) { green = red; blue = red; } else { green = (byte)(128 + Defaults.RandomGenerator.Next(128)); blue = (byte)(128 + Defaults.RandomGenerator.Next(128)); } double xVelocity = X_VELOCITY - 2 * X_VELOCITY * Defaults.RandomGenerator.NextDouble(); double yVelocity = -Y_VELOCITY *Defaults.RandomGenerator.NextDouble(); MagicDot dot = new MagicDot(red, green, blue, size); dot.X = x; dot.Y = y; dot.XVelocity = xVelocity; dot.YVelocity = yVelocity; dot.Gravity = GRAVITY; dot.RunFirework(); _fireworks.Add(dot); LayoutRoot.Children.Add(dot); } }
void MoveFirework() { for (int i = _fireworks.Count - 1; i >= 0; i--) { MagicDot dot = _fireworks[i]; dot.RunFirework(); if (dot.Opacity <= 0.1) { LayoutRoot.Children.Remove(dot); _fireworks.Remove(dot); } } }