Пример #1
0
 /// <summary>
 /// Add the specified number of droidflakes.
 /// </summary>
 public void AddFlakes(int quantity)
 {
     for (int i = 0; i < quantity; ++i)
     {
         flakes.Add(Flake.CreateFlake(Width, droid));
     }
     NumFlakes = numFlakes + quantity;
 }
Пример #2
0
        /// <summary>
        /// Creates a new droidflake in the given xRange and with the given bitmap. Parameters of
        /// location, size, rotation, and speed are randomly determined.
        /// </summary>
        public static Flake CreateFlake(float xRange, Bitmap originalBitmap)
        {
            var rnd = new Random();

            var flake = new Flake();

            // Size each flake with a width between 5 and 55 and a proportional height
            flake.Width = rnd.Next(5, 55);
            var hwRatio = originalBitmap.Height / originalBitmap.Width;

            flake.Height = flake.Width * hwRatio;

            // Position the flake horizontally between the left and right of the range
            flake.X = rnd.Next((int)(xRange - flake.Width));
            // Position the flake vertically slightly off the top of the display
            flake.Y = -rnd.Next(flake.Height, flake.Height * 2);

            // Each flake travels at 50-200 pixels per second
            flake.Speed = rnd.Next(50, 200);

            // Flakes start at -90 to 90 degrees rotation, and rotate between -45 and 45
            // degrees per second
            flake.Rotation      = rnd.Next(-90, 90);
            flake.RotationSpeed = rnd.Next(-45, 45);

            // Get the cached bitmap for this size if it exists, otherwise create and cache one
            if (!bitmapMap.ContainsKey(flake.Width))
            {
                flake.Bitmap           = Bitmap.CreateScaledBitmap(originalBitmap, flake.Width, flake.Height, true);
                bitmapMap[flake.Width] = flake.Bitmap;
            }
            else
            {
                flake.Bitmap = bitmapMap[flake.Width];
            }

            return(flake);
        }
Пример #3
0
        /// <summary>
        /// Creates a new droidflake in the given xRange and with the given bitmap. Parameters of
        /// location, size, rotation, and speed are randomly determined.
        /// </summary>
        public static Flake CreateFlake(float xRange, Bitmap originalBitmap)
        {
            var rnd = new Random();

            var flake = new Flake();

            // Size each flake with a width between 5 and 55 and a proportional height
            flake.Width = rnd.Next(5, 55);
            var hwRatio = originalBitmap.Height / originalBitmap.Width;
            flake.Height = flake.Width * hwRatio;

            // Position the flake horizontally between the left and right of the range
            flake.X = rnd.Next((int)(xRange - flake.Width));
            // Position the flake vertically slightly off the top of the display
            flake.Y = -rnd.Next(flake.Height, flake.Height * 2);

            // Each flake travels at 50-200 pixels per second
            flake.Speed = rnd.Next(50, 200);

            // Flakes start at -90 to 90 degrees rotation, and rotate between -45 and 45
            // degrees per second
            flake.Rotation = rnd.Next(-90, 90);
            flake.RotationSpeed = rnd.Next(-45, 45);

            // Get the cached bitmap for this size if it exists, otherwise create and cache one
            if (!bitmapMap.ContainsKey(flake.Width))
            {
                flake.Bitmap = Bitmap.CreateScaledBitmap(originalBitmap, flake.Width, flake.Height, true);
                bitmapMap[flake.Width] = flake.Bitmap;
            }
            else
            {
                flake.Bitmap = bitmapMap[flake.Width];
            }

            return flake;
        }