/// <summary> /// Initializes the game libraries. /// </summary> /// <param name="owner">Control (Form) that owns the game</param> public GameMain(Control owner) { // Create a Graphics instance #if USE_GDI graphics = new GdiGraphics(owner); #else graphics = new DirectXGraphics(owner); #endif Debug.Assert(graphics != null, "GameMain.GameMain: Failed to initialize Graphics object"); // Create a Input instance gi = new Input(owner); Debug.Assert(gi != null, "GameMain.GameMain: Failed to initialize Input object"); // Register the hardware buttons gi.RegisterAllHardwareKeys(); // Initialize the random number generator rnd = new Random(); // Create a stopwatch instance for timing the frames sw = new Timer.Stopwatch(); Debug.Assert(sw != null, "GameMain.Run: Failed to initialize StopWatch"); }
/// <summary> /// Update the splash screen. /// </summary> public void UpdateSplash() { // Calculate the upper-left corner of the splash screen image int x = (graphics.ScreenWidth - splash.Width) >> 1; int y = (graphics.ScreenHeight - splash.Height) >> 1; // The source region is the entire image src.X = 0; src.Y = 0; src.Width = splash.Width; src.Height = splash.Height; // Draw the splash screen graphics.DrawBitmap(x, y, src, splash); // Flip the back buffers graphics.Flip(); // Store the tick at which this frame started Timer.Stopwatch sw = new Timer.Stopwatch(); Int64 startTick = sw.CurrentTick(); // Draw the splash screen graphics.DrawBitmap(x, y, src, splash); // Draw a "Loading" message as this might take a while graphics.DrawText(graphics.ScreenWidth >> 1, graphics.ScreenHeight - 50, "Loading...", Color.White, ui.Font, FontDrawOptions.DrawTextCenter); // Flip the back buffers graphics.Flip(); if (!introLoaded) { LoadIntro(); } // delay if the splash screen hasn't been up long enough while (sw.DeltaTimeMilliseconds(sw.CurrentTick(), startTick) < TotalSplashTime * 1000.0F) { Thread.Sleep(0); } mode = ModeSwitch.UpdateIntro; }