public void Load(ContentManager Content, string heightMapFileName, float blockScale, float heightScale) { if (!isInitialized) Initialize(); // Load heightMap file Texture2D heightMapTexture = Content.Load<Texture2D>(heightMapFileName); int heightMapSize = heightMapTexture.Width*heightMapTexture.Height; heightMap = new Color[heightMapSize]; heightMapTexture.GetData<Color>(heightMap); this.vertexCountX = heightMapTexture.Width; this.vertexCountZ = heightMapTexture.Height; this.blockScale = blockScale; this.heightScale = heightScale; // Generate terrain mesh GenerateTerrainMesh(); transformation = new Transformation(); // Load effect effect = new TerrainEffect(Game.Content.Load<Effect>(TerrainEffect.EFFECT_FILENAME)); terrainMaterial = new TerrainMaterial(); // Load vertex declaration once this.vertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionNormalTangentBinormalTexture.VertexElements); }
private static GameLevel CreateForestLevel(Game game) { ContentManager Content = game.Content; GameLevel gameLevel = new GameLevel(); // Cameras and lights AddCameras(game, ref gameLevel); gameLevel.LightManager = new LightManager(); gameLevel.LightManager.AmbientLightColor = new Vector3(0.1f, 0.1f, 0.1f); gameLevel.LightManager.Add("MainLight", new PointLight(new Vector3(10000, 10000, 10000), new Vector3(0.2f, 0.2f, 0.2f))); gameLevel.LightManager.Add("CameraLight", new PointLight(Vector3.Zero, Vector3.One)); game.Services.AddService(typeof(CameraManager), gameLevel.CameraManager); game.Services.AddService(typeof(LightManager), gameLevel.LightManager); // Terrain gameLevel.Terrain = new Terrain(game); gameLevel.Terrain.Initialize(); gameLevel.Terrain.Load(game.Content, "Terrain1", 8.0f, 1.0f); // Terrain material TerrainMaterial terrainMaterial = new TerrainMaterial(); terrainMaterial.LightMaterial = new LightMaterial( new Vector3(0.8f), new Vector3(0.3f), 32.0f); terrainMaterial.DiffuseTexture1 = GetTextureMaterial(game, "Terrain1", new Vector2(40, 40)); terrainMaterial.DiffuseTexture2 = GetTextureMaterial(game, "Terrain2", new Vector2(25, 25)); terrainMaterial.DiffuseTexture3 = GetTextureMaterial(game, "Terrain3", new Vector2(15, 15)); terrainMaterial.DiffuseTexture4 = GetTextureMaterial(game, "Terrain4", Vector2.One); terrainMaterial.AlphaMapTexture = GetTextureMaterial(game, "AlphaMap", Vector2.One); terrainMaterial.NormalMapTexture = GetTextureMaterial(game, "Rockbump", new Vector2(128, 128)); gameLevel.Terrain.Material = terrainMaterial; game.Services.AddService(typeof(Terrain), gameLevel.Terrain); // Sky gameLevel.SkyDome = new SkyDome(game); gameLevel.SkyDome.Initialize(); gameLevel.SkyDome.Load("SkyDome"); gameLevel.SkyDome.TextureMaterial = GetTextureMaterial(game, "SkyDome", Vector2.One); // Player gameLevel.Player = new Player(game, UnitTypes.PlayerType.Frog); gameLevel.Player.Initialize(); gameLevel.Player.Transformation = new Transformation(new Vector3(50, 0, 50), new Vector3(0, 0, 0), 2*Vector3.One); gameLevel.Player.TransformationOld = gameLevel.Player.Transformation; gameLevel.Player.AnimatedModel.AnimationSpeed = 1.0f; // Player chase camera offsets gameLevel.Player.ChaseOffsetPosition = new Vector3[2]; gameLevel.Player.ChaseOffsetPosition[0] = new Vector3(0.0f, 7.0f, -3.0f); gameLevel.Player.ChaseOffsetPosition[1] = new Vector3(3.0f, 4.0f, 0.0f); // Enemies gameLevel.EnemyList = ScatterEnemies(game, 10, 50, 200, gameLevel.Player); // Mosquitos gameLevel.MosquitoList = ScatterMosquitos(game, 15, 10, 300, gameLevel.Player); // StaticUnits //gameLevel.StaticUnitList = ScatterStaticUnits(game, 10, 50, 300, gameLevel.Player); gameLevel.StaticUnitList = PlaceStaticUnits(game, "Forest"); gameLevel.Bound2D = ReadBounding2D("Forest"); return gameLevel; }