//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace ElementalGame { #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using System.Xml; using System.Diagnostics; #endregion // Game flow is the top of the Multiplayer Game Mode public class GameFlow { public enum GameType { NONE_SELECTED, STORY_MODE, LAST_MAN_STANDING, POINT_DEATHMATCH, SURVIVAL }; public static GameType gameType = GameType.NONE_SELECTED; // Our 4 main components Collision _collision; // Procedural class that handles collision detection Renderer _renderer; // Renders the scene once for each viewport ObjectLibrary _objectLibrary; // A scenegraph/collections class, contains all GameObject instants GameRules gameRules; public static int botIntelligence; public static int maxNumberOfKills; public static int numberOfBots; public static int numberOfHumansActive; public float gameScreenRotation = 0.0f; Viewport demoViewport; public GameFlow() { XML.LoadSystem(); // Create the Object Library objectLibrary = new ObjectLibrary(); // Create the viewport for the terrain demoViewport = new Viewport(); // Top Left = 260, 96 // Top Right = 710, 96 // Bottom Left = 260, 435 // Bottom Right = 710, 435 demoViewport.X = 260 * XML.SystemSettings.GAME_WINDOW_WIDTH / 800; demoViewport.Y = 96 * XML.SystemSettings.GAME_WINDOW_HEIGHT / 600; demoViewport.Width = 450 * XML.SystemSettings.GAME_WINDOW_WIDTH / 800; demoViewport.Height = 339 * XML.SystemSettings.GAME_WINDOW_HEIGHT / 600; demoViewport.MinDepth = ElementalGame.defaultViewport.MinDepth; demoViewport.MaxDepth = ElementalGame.defaultViewport.MaxDepth; } // Load all in-game variables public void LoadGame() { // Set up Collision and Renderer _collision = new Collision(); _renderer = new Renderer(); gameRules = new GameRules(); } // Load the Terrain Demo Screen public void LoadTerrainDemo(string xmlFileName) //GraphicsDeviceManager graphics, string xmlFileName, ContentManager content) { _objectLibrary.LoadLevel_Stage1(xmlFileName); } // Draw the Terrain Demo Screen public void DrawTerrainDemo(GraphicsDevice graphicsDevice, float dt) { // Top Left = 260, 96 // Top Right = 710, 96 // Bottom Left = 260, 435 // Bottom Right = 710, 435 graphicsDevice.Viewport = demoViewport; graphicsDevice.Clear(Color.Black); gameScreenRotation += dt; if (gameScreenRotation > Math.PI * 2.0f) { gameScreenRotation -= (float)Math.PI * 2.0f; } Matrix matrix = Matrix.Identity; float dx = (float)((Terrain.collisionMapSize / 2.0f) * Math.Sin(gameScreenRotation)) + (Terrain.collisionMapSize / 2.0f); float dz = (float)((Terrain.collisionMapSize / 2.0f) * Math.Cos(gameScreenRotation)) + (Terrain.collisionMapSize / 2.0f); // Calculate the player's ModelView Matrix Matrix matrixModelView = Matrix.CreateLookAt(new Vector3(dx, 1000.0f, dz), new Vector3(Terrain.collisionMapSize / 2, 0, Terrain.collisionMapSize / 2), Vector3.Up); // Calculate the player's Projection Matrix Matrix matrixProjection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 3.0f, demoViewport.Width / demoViewport.Height, 0.3f, 100000f); // Set shader parameters required by the demo ShaderParameters.light0.SetValue(XML.LevelSettings.lightInfo1); ShaderParameters.light1.SetValue(XML.LevelSettings.lightInfo2); ShaderParameters.fogColor.SetValue(XML.LevelSettings.fogColor); ShaderParameters.fogDensity.SetValue(XML.LevelSettings.fogDensity); ShaderParameters.ViewProj.SetValue(matrixModelView * matrixProjection); ShaderParameters.playerIsDead.SetValue(false); if (XML.LevelSettings.fogDensity != 0.0f) { ShaderParameters.fogDensity.SetValue(0.0003f); } ShaderParameters.EyePostion.SetValue(Matrix.Invert(matrixModelView)); _objectLibrary.skySphere.Draw(new ModelManager()); _objectLibrary.terrain.Draw(new ModelManager()); } // Load the Player Demo Screen public void LoadPlayerDemo() { } // Draw the Player Demo Screen public void DrawPlayerDemo(GraphicsDevice graphicsDevice, float dt, int playerIndex) { graphicsDevice.Viewport = demoViewport; graphicsDevice.Clear(Color.Black); gameScreenRotation += dt; if (gameScreenRotation > Math.PI * 2.0f) { gameScreenRotation -= (float)Math.PI * 2.0f; } Matrix matrix = Matrix.CreateScale(_objectLibrary.humans[playerIndex].mass.scale); float dx = (float)((XML.PlayerSettings.DEFAULT_PLAYER_HEIGHT * 0.5f) * Math.Sin(gameScreenRotation)); float dz = (float)((XML.PlayerSettings.DEFAULT_PLAYER_HEIGHT * 0.5f) * Math.Cos(gameScreenRotation)); // Calculate the player's ModelView Matrix Matrix matrixModelView = Matrix.CreateLookAt(new Vector3(dx, 5.0f, dz), new Vector3(0, 5.0f, 0), Vector3.Up); // Calculate the player's Projection Matrix Matrix matrixProjection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 3.0f, demoViewport.Width / demoViewport.Height, 0.3f, 100000f); Renderer.matrixModelView = matrixModelView; Renderer.matrixProjection = matrixProjection; BoundingFrustum frustum = new BoundingFrustum(matrixModelView * matrixProjection); ShaderParameters.light0.SetValue(XML.LevelSettings.lightInfo1); ShaderParameters.light1.SetValue(XML.LevelSettings.lightInfo2); ShaderParameters.fogColor.SetValue(new Vector4(0.0f)); ShaderParameters.fogDensity.SetValue(0.0f); ShaderParameters.World.SetValue(matrix); ShaderParameters.ViewProj.SetValue(matrixModelView * matrixProjection); ShaderParameters.playerIsDead.SetValue(false); _objectLibrary.skySphere.Draw(new ModelManager()); _objectLibrary.humans[playerIndex].DrawPlayerDemo(matrixModelView, matrixProjection); } // Load all graphics and models for GameObjects public void Load() { // Call Load Sequence _objectLibrary.LoadLevel_Stage2(); // Reset Survival Stopwatch if (gameType == GameType.SURVIVAL) { gameRules.survivalRespawnTimer = new Stopwatch(); gameRules.survivalRespawnTimer.Start(); } } // Call the Update sequence public void Update(float dt, MenuSystem menuSystem, SpriteBatch spriteBatch) { if (GameRules.storyElement == GameRules.StoryElement.LIVEACTION || gameType != GameType.STORY_MODE) { _collision.UpdateCollision(_objectLibrary, dt); _objectLibrary.UpdatePosition(dt); } gameRules.CheckForGameOver(this, _objectLibrary, menuSystem, gameType); gameRules.CheckForRespawn(_objectLibrary, gameType); } // Call the Draw sequence public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, List viewportList, MenuSystem menuSystem) { // Draw Cutscene if (GameRules.storyElement == GameRules.StoryElement.CUTSCENE) { if (GameRules.cutSceneIndex == 0) { menuSystem.scene1.Draw(spriteBatch); } if (GameRules.cutSceneIndex == 1) { menuSystem.scene2.Draw(spriteBatch); } if (GameRules.cutSceneIndex == 2) { menuSystem.scene3.Draw(spriteBatch); } if (GameRules.cutSceneIndex == 3) { menuSystem.scene4.Draw(spriteBatch); } if (GameRules.cutSceneIndex == 4) { menuSystem.scene5.Draw(spriteBatch); } } else { // Draw Scene _renderer.Draw(spriteBatch, _objectLibrary, viewportList); } } public void StopRumble() { if (objectLibrary != null && objectLibrary.humans != null && objectLibrary.bots != null) { for (int i = 0; i < objectLibrary.humans.Count; i++) { if (objectLibrary.humans[i] != null) { objectLibrary.humans[i].StopRumble(); } } } } // Accessors - Required by C# Compiler public Collision collision { get { return _collision; } set { _collision = value; } } public Renderer renderer { get { return _renderer; } set { renderer = value; } } public ObjectLibrary objectLibrary { get { return _objectLibrary; } set { _objectLibrary = value; } } } }