public AssetLoadScreen() { // Initialize random number generator. random = new JoshoRandom(); // Set the blink time so we know when to blink. blinkTime = TimeSpan.FromSeconds(0.1); // Let's load. loadingComplete = false; isLoading = false; // Set the first color to white. color1 = Color.White; myColor = Color.White; // Set the second color to a random color. color2 = GenerateRandomColorWithoutAlpha(); // This BackgroundWorker will be responsible for loading the assets and doing other initialization steps on a separate thread. bgWorker = new BackgroundWorker(); // Add event handler to the method that's going to do work! bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork); // Add event handler to when the thread is done working. bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted); }
/// <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++; } }
public void Initialize() { random = new JoshoRandom(); this.snowTexture = Assets.snowflakeTexture; this.w = screenManagerInstance.Game.Window.ClientBounds.Width; this.h = screenManagerInstance.Game.Window.ClientBounds.Height; // Set the snow's quit point. It's the bottom of the screen plus the texture's height so it looks like the snow goes completely off screen. this.quitPoint = new Point(0, this.Height + this.snowTexture.Height); // Set the snow's start point. It's the top of the screen minus the texture's height so it looks like it comes from somewhere, rather than appearing this.startPoint = new Point(0, 0 - this.snowTexture.Height); isSnowing = true; }
public void Initialize() { random = new JoshoRandom(); this.snowTexture = Assets.snowflakeTexture; //this.w = screenManagerInstance.Game.Window.ClientBounds.Width; //this.h = screenManagerInstance.Game.Window.ClientBounds.Height; this.w = screenManagerInstance.GraphicsDevice.Viewport.TitleSafeArea.Width; this.h = screenManagerInstance.GraphicsDevice.Viewport.TitleSafeArea.Height; // Set the snow's quit point. It's the bottom of the screen plus the texture's height so it looks like the snow goes completely off screen. this.quitPoint = new Point(0, this.Height + this.snowTexture.Height); // Set the snow's start point. It's the top of the screen minus the texture's height so it looks like it comes from somewhere, rather than appearing. this.startPoint = new Point(0, 0 - this.snowTexture.Height); isSnowing = true; for (int i = 0; i < this.snow.Length; i++) { this.snow[i] = new Snowflake(this.startPoint); this.snow[i].Initialize(); } }
public Snowflake(Point startingPosition, JoshoRandom rand) { this.Position = startingPosition; this.random = rand; this.Initialize(); }
public Snowflake(Point startingPosition) { this.Position = startingPosition; this.random = new JoshoRandom(); this.Initialize(); }