public override void Initialize() { cameraManager = Game.Services.GetService(typeof(CameraManager)) as CameraManager; lightManager = Game.Services.GetService(typeof(LightManager)) as LightManager; if (cameraManager == null || lightManager == null) throw new InvalidOperationException(); isInitialized = true; base.Initialize(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Random random = new Random(); Vector3 position = new Vector3(); //Main Commander (Player) //Enemy Commander (Computer) Player = new Commander(); AI = new AICommander(); // Camera Manager cameraManager = new CameraManager(); Services.AddService(typeof(CameraManager), cameraManager); float aspectRatio = GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height; // Light Manager lightManager = new LightManager(); lightManager.AmbientLightColor = new Vector3(0.3f, 0.3f, 0.3f); Services.AddService(typeof(LightManager), lightManager); // Light 1 lightManager.Add("Light1", new PointLight(new Vector3(1500, 1500, 1500), Vector3.One)); // Camera 1 - ThirdPerson Camera RTSCamera camera1 = new RTSCamera(GraphicsDevice, new Vector3(0, 0, 600), Vector3.Forward); camera1.aspectRatio = aspectRatio; cameraManager.Add("Camera1", camera1); // Camera 2 - MoveableCamera Camera position = new Vector3(500, 0, 75); position.Y = position.Y + 30; MoveableCamera camera2 = new MoveableCamera(GraphicsDevice, new Vector3(0, 0, 400), 45.0f, 30.0f); camera2.aspectRatio = aspectRatio; camera2.CameraPosition = position; camera2.CameraTarget = camera2.CameraPosition + new Vector3(-3.0f, 0.0f, -1.0f); cameraManager.Add("Camera2", camera2); // Terrain terrain = new Terrain(this); terrain.Load(Content, @"Terrains\heightmap1", 12.0f, 1f); // Terrain material TerrainMaterial material = new TerrainMaterial(); material.DiffuseTexture1 = LoadTextureMaterial(@"grass", new Vector2(100, 100)); material.LightMaterial = new LightMaterial(new Vector3(0.8f), new Vector3(0.3f), 32); terrain.Material = material; worldModel = new WorldModel((int)terrain.EndPosition.X, (int)terrain.EndPosition.Y, (int)terrain.EndPosition.Y); //add Player Marine marine; for (int x = 0; x < 10; x++) { position = new Vector3(worldModel.MaxX / 2 + 20 * x, 0, worldModel.MaxY / 2); position.Y = terrain.GetHeight(position.X, position.Z); marine = new Marine(GraphicsDevice, Content, @"Models\Dude", @"Images\dude1", position, new Vector3(worldModel.MaxX, worldModel.MaxY, worldModel.MaxZ), Player) { Scale = 0.3f, Name = "Ranger" + x, ViewRange = 100, AttackRange = 50, AttackDamage = 10, AttackCooldown = 2, CurrentHealth = 100 }; worldModel.Models.Add(marine); } //add AI position = new Vector3(worldModel.MaxX / 2, 0, worldModel.MaxY / 2+100); position.Y = terrain.GetHeight(position.X, position.Z); marine = new Marine(GraphicsDevice, Content, @"Models\Dude", @"Images\dude2", position, new Vector3(worldModel.MaxX, worldModel.MaxY, worldModel.MaxZ), AI) { Scale = 0.3f, Name = "dude20", ViewRange = 100, AttackRange = 50, AttackDamage = 10, AttackCooldown = 2, CurrentHealth = 100 }; worldModel.Models.Add(marine); //add rocks GameModel gameModel; for (int x = 0; x < 100; x++) { position = new Vector3(random.Next(worldModel.MaxX), 0, random.Next(worldModel.MaxY)); position.Y = terrain.GetHeight(position.X, position.Z); gameModel = new Marine(GraphicsDevice, Content, @"Models\MainTree", @"Images\dude1", position, new Vector3(worldModel.MaxX, worldModel.MaxY, worldModel.MaxZ), Player) { Scale = random.Next(10)*0.03f, Name = "dude" + x, ViewRange = 100, AttackRange = 50, AttackDamage = 10, AttackCooldown = 2, CurrentHealth = 100 }; worldModel.Models.Add(gameModel); } //add trees cameraManager.ActiveCamera.modelPosition = worldModel.Models[0].Position; worldModel.SpacialIndex.updateGrid(); //Other Methods //Top most menu system topMenu = new TopMenu(Content, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); botMenu = new BotMenu(graphics.GraphicsDevice, Content, new Rectangle(0,0,graphics.PreferredBackBufferWidth,graphics.PreferredBackBufferHeight)); Player.LoadDefaults(); AI.LoadDefaults(); //List<Unit> res=worldModel.SpacialIndex.getNearbyUnits(Player.Units[1]); }