private static void AddCameras(Game game, ref GameLevel gameLevel) { float aspectRate = (float)game.GraphicsDevice.Viewport.Width / game.GraphicsDevice.Viewport.Height; ThirdPersonCamera followCamera = new ThirdPersonCamera(); followCamera.SetPerspectiveFov(60.0f, aspectRate, 0.1f, 2000); followCamera.SetChaseParameters(3.0f, 9.0f, 7.0f, 14.0f); ThirdPersonCamera fpsCamera = new ThirdPersonCamera(); fpsCamera.SetPerspectiveFov(45.0f, aspectRate, 0.1f, 2000); fpsCamera.SetChaseParameters(5.0f, 6.0f, 6.0f, 6.0f); gameLevel.CameraManager = new CameraManager(); gameLevel.CameraManager.Add("FollowCamera", followCamera); gameLevel.CameraManager.Add("FPSCamera", fpsCamera); }
protected override void LoadContent() { // Create SpriteBatch and add services spriteBatch = new SpriteBatch(GraphicsDevice); // Font 2D spriteFont = Game.Content.Load<SpriteFont>(GameAssetsPath.FONTS_PATH + "BerlinSans"); // Weapon target weaponTargetTexture = Game.Content.Load<Texture2D>(GameAssetsPath.TEXTURES_PATH + "weaponTarget"); // Weapon target 2 weaponTargetTexture2 = Game.Content.Load<Texture2D>(GameAssetsPath.TEXTURES_PATH + "weaponTarget2"); // Weapon target 3 firePosTexture = Game.Content.Load<Texture2D>(GameAssetsPath.TEXTURES_PATH + "firePos"); // Health Bar healthBar = Game.Content.Load<Texture2D>(GameAssetsPath.TEXTURES_PATH + "healthBar"); // Load game level gameLevel = LevelCreator.CreateLevel(Game, currentLevel); base.LoadContent(); }
public override void Update(GameTime gameTime) { // Restart game if (gameLevel.Player.IsDead || numEnemiesAlive == 0) { //Game.Exit(); gameLevel = LevelCreator.CreateLevel(Game, currentLevel); numEnemiesAlive = gameLevel.EnemyList.Count; numMosquitosAlive = gameLevel.MosquitoList.Count; } UpdateInput(); // Update player gameLevel.Player.Update2DCollision(gameLevel.Bound2D); gameLevel.Player.Update(gameTime); UpdateWeaponTarget(); // Update camera BaseCamera activeCamera = gameLevel.CameraManager.ActiveCamera; activeCamera.Update(gameTime); // Update light position PointLight cameraLight = gameLevel.LightManager["CameraLight"] as PointLight; cameraLight.Position = activeCamera.Position; // Update enemies foreach (Enemy enemy in gameLevel.EnemyList) { if (enemy.BoundingSphere.Intersects(activeCamera.Frustum) || enemy.State == Enemy.EnemyState.ChasePlayer || enemy.State == Enemy.EnemyState.AttackPlayer) { enemy.Update2DCollision(gameLevel.Bound2D); enemy.Update(gameTime); } } // Update mosquito foreach (Mosquito mosquito in gameLevel.MosquitoList) { if (mosquito.BoundingSphere.Intersects(activeCamera.Frustum)) { mosquito.Update2DCollision(gameLevel.Bound2D); mosquito.Update(gameTime); } } // Update stat units foreach (StaticUnit statUnit in gameLevel.StaticUnitList) { if (statUnit.BoundingSphere.Intersects(activeCamera.Frustum)) { statUnit.Update(gameTime); } } // Update scene objects gameLevel.SkyDome.Update(gameTime); gameLevel.Terrain.Update(gameTime); base.Update(gameTime); }
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; }