/// <summary> /// Draw the falling snow. /// </summary> /// <param name="spriteBatch">SpriteBatch that has been initialized and began.</param> public void Draw(SpriteBatch spriteBatch) { // If it's not supposed to be snowing, then exit. if (!isSnowing) return; // This will be used as the index within our snow array. int i; // NOTE: The following conditional is not exactly the best "initializer." // If snow has not been initialized. if (this.snow[0] == new Point(0, 0)) { // Make the random a new random this.random = new JoshoRandom(); // For every snow particle within our snow array, for (i = 0; i < this.snow.Length; i++) { // Give it a new, random x and y. This will give the illusion that it was already snowing and won't cluster the particles this.snow[i] = new Point((random.NextInt(0, (this.Width - this.snowTexture.Width))), (random.NextInt(0, (this.Height)))); } } // Reinitialize the random number generator. this.random = new JoshoRandom(); // Go back to the start. i = 0; // Begin displaying the snow foreach (Point snowPnt in this.snow) { // Get the exact rectangle for the snow particle Rectangle snowParticle = new Rectangle( snowPnt.X, snowPnt.Y, this.snowTexture.Width, this.snowTexture.Height); // Draw the snow particle (change white if you want any kind of tinting) spriteBatch.Draw(this.snowTexture, snowParticle, Color.White * random.NextInt(128, 255)); //Make the current particle go down, but randomize it for a staggering snow this.snow[i].Y += random.NextInt(0, 5); // Make sure the point's location is not below quit point's. if (this.snow [i].Y >= this.quitPoint.Y) { // If it is, give it a random X value, and the starting point variable's Y value. this.snow [i] = new Point ((random.NextInt(0, (this.Width - this.snowTexture.Width))), this.startPoint.Y); } // Go to the next snowflake (or snow particle). i++; } }