} // LoadAllLevels() #endregion #region Unit Testing #if DEBUG #region Generate level files #if !XBOX360 /// <summary> /// Generate landscape height file. Usually we would just load the /// LandscapeGridHeights.png file and use the data directly. But sadly /// the Xbox360 does not support the Texture.GetData method. /// </summary> public static void GenerateLevelFiles() { TestGame.Start("GenerateLevelFiles", delegate { // Ok, load map grid heights. We can't load this as a Bitmap // because we don't have the System.Drawing namespace in XNA. // We also can't use BitmapContent or PixelBitmapContent<Color> from // the Microsoft.XNA.Framework.Content.Pipeline namespace because // our content is not compatible with that (its just a texture). // Note: Doesn't work on the Xbox360 (no GetData method available)! string[] levelNames = new string[] { "Easy Flight", "Lost Civilization", "The Revenge", "Valley of Death", }; Texture2D[] texs = new Texture2D[] { Texture2D.FromFile(BaseGame.Device, "Levels\\" + levelNames[0] + ".png"), Texture2D.FromFile(BaseGame.Device, "Levels\\" + levelNames[1] + ".png"), Texture2D.FromFile(BaseGame.Device, "Levels\\" + levelNames[2] + ".png"), Texture2D.FromFile(BaseGame.Device, "Levels\\" + levelNames[3] + ".png"), }; int levelNum = 0; foreach (Texture2D tex in texs) { int width = tex.Width; int height = tex.Height; // With help of GetData we can get to the data. Color[] texData = new Color[width * height]; tex.GetData <Color>(texData, 0, width * height); // And finally save it into the content directory FileStream file = File.Create("Content\\" + levelNames[levelNum++] + ".level"); BinaryWriter writer = new BinaryWriter(file); writer.Write(width); writer.Write(height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { writer.Write(texData[x + y * width].R); writer.Write(texData[x + y * width].G); writer.Write(texData[x + y * width].B); } // for for } file.Close(); // That's it already! } // foreach (tex) }, null); } // GenerateLandscapeHeightFile()
} // Update() #endregion #region Unit Testing #if DEBUG /// <summary> /// Test space camera /// </summary> public static void TestSpaceCamera() { Model testModel = null; TestGame.Start("TestSpaceCamera", delegate // Init { testModel = new Model("asteroid4"); }, delegate // Render loop { // Just render testModel in the middle of the scene. testModel.Render(Vector3.Zero); TextureFont.WriteText(1, 20, "MoveFactorPerSecond=" + BaseGame.MoveFactorPerSecond); }); } // TestSpaceCamera()
} // Start(renderCode) #endregion #region Unit Testing #if DEBUG #region TestEmptyGame /// <summary> /// Test empty game /// </summary> public static void TestEmptyGame() { TestGame.Start(null); } // TestEmptyGame()
} // SetupScene(sceneNumber) #endregion #region Test asteroid manager physics. Press 1-7 to start physics scenes. /// <summary> /// Test asteroid manager physics. Press 1-7 to start physics scenes. /// </summary> public void TestAsteroidPhysicsSmallScene() { TestGame.Start("TestAsteroidPhysicsSmallScene", delegate { asteroidManager = new GameAsteroidManager( Level.LoadAllLevels()[0]); asteroidModel = asteroidManager.asteroidModels[0]; //new Model("Asteroid1.X"); SetupScene(0); }, delegate { BaseGame.GlowShader.Start(); // Render sky cube map as our background. BaseGame.skyCube.RenderSky(1.0f, BaseGame.SkyBackgroundColor); BaseGame.camera.FreeCamera = true; BaseGame.EnableAlphaBlending(); // Press 1-7 to start physics scenes. if (Input.KeyboardKeyJustPressed(Keys.D1)) { SetupScene(0); } if (Input.KeyboardKeyJustPressed(Keys.D2)) { SetupScene(1); } if (Input.KeyboardKeyJustPressed(Keys.D3)) { SetupScene(2); } if (Input.KeyboardKeyJustPressed(Keys.D4)) { SetupScene(3); } if (Input.KeyboardKeyJustPressed(Keys.D5)) { SetupScene(4); } if (Input.KeyboardKeyJustPressed(Keys.D6)) { SetupScene(5); } if (Input.KeyboardKeyJustPressed(Keys.D7)) { SetupScene(6); } for (int z = 0; z < NumberOfSectors; z++) { //for (int y = 0; y < NumberOfSectors; y++) for (int x = 0; x < NumberOfSectors; x++) { // Update all positions for this sector foreach (Asteroid asteroid in asteroidManager.sectorAsteroids[z, x]) { asteroid.UpdateMovement(BaseGame.MoveFactorPerSecond); } // Handle physics (only calculate 50% per frame) //always: if ((z + x) % 2 == BaseGame.TotalFrames % 2) asteroidManager.HandleSectorPhysics(x, z, 0, 0); } // asteroidModel } // Make sure we start the mesh render manager for this frame. // It will copy all models from last frame over to this frame. //obs, handled in render now! BaseGame.MeshRenderManager.Init(); // Render physics asteroids ourselfs for (int z = 0; z < NumberOfSectors; z++) { //for (int y = 0; y < NumberOfSectors; y++) for (int x = 0; x < NumberOfSectors; x++) { //if (x <= 1 && y <= 1 && z <= 1) if (asteroidManager.sectorIsVisible[z, x]) { foreach (Asteroid asteroid in asteroidManager.sectorAsteroids[z, x]) { asteroidModel.Render(asteroid.RenderMatrix); } // asteroidModel } } } }); } // TestAsteroidPhysicsSmallScene()