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; using System.Threading; #endregion /// /// This Game Class is essentially a wiring access panel /// Configurations for various aspects of Game and Engine are stored here /// To create new xml settings, create a var in appropriate struct /// Then edit appropriate method to read and set the xml value into the struct /// In GameObject, then access the variable by calling XML.struct.variable /// public static class XML { public static XmlNode terrainNode = null; public static XmlNode physicsNode = null; public static XmlNode skyNode = null; public static XmlNode fogNode = null; public static XmlNode musicNode = null; public static XmlNode propsNode = null; public static XmlNode particlesNode = null; public static XmlNode gpuObjectNode = null; public static XmlNode[] humanNodes = new XmlNode[4]; public static XmlNode[] botNodes; // ============= NEW CLASS =================== // Called From ElementalGame public struct SystemSettings { public static int GAME_WINDOW_WIDTH = 800; public static int GAME_WINDOW_HEIGHT = 600; public static int ANTI_BURN_TIMER = 60000; public static int MAX_HUMANS = 4; public static int TOTAL_PLAYERS = 0; // Pause Menu Options public static bool enableShadowMap1 = true; public static bool enableShadowMap2 = true; public static bool enableTerrainBumpMapping = true; public static bool enableTerrainMultiTexturing = true; public static int numberOfTerrainTextures = 4; public static bool singleLightSource = false; public static bool music = true; public static bool soundFX = true; } public static void LoadSystem() { try { // Load physics, music, and fog XmlDocument reader = new XmlDocument(); reader.Load("_xml/SystemSettings/SystemSettings.xml"); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode settingsNode in allNodes) { if (settingsNode.Name == "GameSettings") { XmlNodeList settingsNodes = settingsNode.ChildNodes; foreach (XmlNode node in settingsNodes) { if (node.Name == "EnableShadowMap1") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.enableShadowMap1 = true; } else { SystemSettings.enableShadowMap1 = false; } } else if (node.Name == "EnableShadowMap2") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.enableShadowMap2 = true; } else { SystemSettings.enableShadowMap2 = false; } } else if (node.Name == "EnableTerrainBumpMapping") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.enableTerrainBumpMapping = true; } else { SystemSettings.enableTerrainBumpMapping = false; } } else if (node.Name == "EnableTerrainMultiTexturing") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.enableTerrainMultiTexturing = true; } else { SystemSettings.enableTerrainMultiTexturing = false; } } else if (node.Name == "NumberOfTerrainTextures") { int value = int.Parse(node.Attributes["value"].Value); if (value == 4) { SystemSettings.numberOfTerrainTextures = 4; } else if (value == 3) { SystemSettings.numberOfTerrainTextures = 3; } else { SystemSettings.numberOfTerrainTextures = 2; } } else if (node.Name == "SingleLightSource") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.singleLightSource = true; } else { SystemSettings.singleLightSource = false; } } else if (node.Name == "MusicEnabled") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.music = true; } else { SystemSettings.music = false; } } else if (node.Name == "SoundEffects") { string value = node.Attributes["value"].Value; if (value == "Yes") { SystemSettings.soundFX = true; } else { SystemSettings.soundFX = false; } } } } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); return; } ElementalGame.menuSystem.pauseScreen.SetDefaults(); } public static void SaveSystem() { XmlTextWriter settingsFile = new XmlTextWriter("_xml/SystemSettings/SystemSettings.xml", null); settingsFile.Formatting = Formatting.Indented; settingsFile.WriteStartDocument(); settingsFile.WriteStartElement("SystemSettings"); settingsFile.WriteStartElement("EnableShadowMap1"); if (SystemSettings.enableShadowMap1) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("EnableShadowMap2"); if (SystemSettings.enableShadowMap2) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("EnableTerrainBumpMapping"); if (SystemSettings.enableTerrainBumpMapping) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("EnableTerrainMultiTexturing"); if (SystemSettings.enableTerrainMultiTexturing) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("NumberOfTerrainTextures"); if (SystemSettings.numberOfTerrainTextures == 4) { settingsFile.WriteAttributeString("value", "4"); } else if (SystemSettings.numberOfTerrainTextures == 3) { settingsFile.WriteAttributeString("value", "3"); } else { settingsFile.WriteAttributeString("value", "2"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("SingleLightSource"); if (SystemSettings.singleLightSource) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("MusicEnabled"); if (SystemSettings.music) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteStartElement("SoundEffects"); if (SystemSettings.soundFX) { settingsFile.WriteAttributeString("value", "Yes"); } else { settingsFile.WriteAttributeString("value", "No"); } settingsFile.WriteEndElement(); settingsFile.WriteEndElement(); settingsFile.WriteEndDocument(); settingsFile.Flush(); settingsFile.Close(); } // ============= NEW CLASS =================== // Called From GameFlow public struct GameSettings { public static int collisionSearchArea = 2; public static int drawSearchArea = 40; public static int MAX_LEVELS = 4; public static int STORYMODE_NUM_KEYS_TO_COLLECT = 10; public static float HEALTH_BOOST_FOR_KEY = 5.0f; public static float PARTICLE_SOUND_TIME_LIMIT = 10000.0f; } public static void LoadGame() { } // ============= NEW CLASS =================== // Load Level Screen public struct LevelInfo { public string name; public string description; public string filepath; } public static List levelInfo; public static void LoadLevelIndex() { string LevelXMLFile = "_xml/LevelSettings/Levels.xml"; levelInfo = new List(); try { // Load physics, music, and fog XmlDocument reader = new XmlDocument(); reader.Load(LevelXMLFile); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode levelNode in allNodes) { if (levelNode.Name == "levels") { XmlNodeList levelNodes = levelNode.ChildNodes; foreach (XmlNode node in levelNodes) { if (levelInfo.Count >= GameSettings.MAX_LEVELS) { break; } if (node.Name == "level") { LevelInfo level = new LevelInfo(); level.name = node.Attributes["name"].Value; level.filepath = node.Attributes["xmlFile"].Value; level.description = node.Attributes["description"].Value; levelInfo.Add(level); } } } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); return; } } // Called From ObjectLibrary public struct LevelSettings { public static float TERRAIN_FRICTION = 0.0f; public static float fogDensity = 0; public static float[] fogColor = { 1.0f, 1.0f, 1.0f, 0.1f }; public static float zMaxDepth = 1000.0f; public static int numberOfHumans; // Number humans in the game public static int MAX_NUMBER_OF_BOTS = 50; // The most bots there can be public static double lightMoveAngle1 = 0; public static double lightMoveAngle2 = 0; public static float lightDistance1 = 0.0f; public static float lightDistance2 = 0.0f; public static float LIGHT_MOVE_SPEED1 = 0.0f; public static float LIGHT_MOVE_SPEED2 = 0; public static List darkMatter; public static int darkMatterCount = 100000; public static int darkMatterIterator = 0; // Distance to start particle from player that shot it public static float PARTICLE_START_DISTANCE = 20.0f; // Attack Variables public static float DIRECT_ATTACK_FORCE = 150000; public static Matrix lightInfo1 = new Matrix(512.0f, 3072.0f, 512.0f, 0.0f, // Position 0.3f, 0.3f, 0.3f, 1.0f, // Ambient 0.5f, 0.5f, 0.5f, 1.0f, // Diffuse 0.5f, 0.5f, 0.5f, 1.0f); // Specular public static Matrix lightInfo2 = new Matrix(7680.0f, 3072.0f, 7680.0f, 0.0f, // Position 0.3f, 0.3f, 0.3f, 1.0f, // Ambient 0.5f, 0.5f, 0.5f, 1.0f, // Diffuse 0.5f, 0.5f, 0.5f, 1.0f); // Specular } public static void LoadLevel(string xmlFileName) { try { // Load physics, music, and fog XmlDocument reader = new XmlDocument(); reader.Load(xmlFileName); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode levelNode in allNodes) { if (levelNode.Name == "level") { string levelName = levelNode.Attributes["name"].Value; XmlNodeList levelNodes = levelNode.ChildNodes; foreach (XmlNode node in levelNodes) { if (node.Name == "physics") { physicsNode = node; } else if (node.Name == "terrain") { terrainNode = node; } else if (node.Name == "sky") { skyNode = node; } else if (node.Name == "fog") { fogNode = node; } if (node.Name == "music") { musicNode = node; } else if (node.Name == "humans") { foreach (XmlNode humanNode in node.ChildNodes) { try { int id = int.Parse(humanNode.Attributes["id"].Value); humanNodes[id] = humanNode; } catch { System.Diagnostics.Debug.WriteLine("Error reading player attributes"); return; } } } else if (node.Name == "props") { propsNode = node; } else if (node.Name == "bots") { botNodes = new XmlNode[XML.LevelSettings.MAX_NUMBER_OF_BOTS]; foreach (XmlNode botNode in node.ChildNodes) { try { int id = int.Parse(botNode.Attributes["id"].Value); botNodes[id] = botNode; } catch { System.Diagnostics.Debug.WriteLine("Error reading bot attributes"); return; } } } else if (node.Name == "particles") { particlesNode = node; } else if (node.Name == "gpuObjects") { gpuObjectNode = node; } } } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); return; } // Physics properties if (XML.physicsNode != null) { Mass.gravityForce = float.Parse(XML.physicsNode.Attributes["gravity"].Value); Mass.accelDueToGravity = new Vector3(0.0f, Mass.gravityForce, 0.0f); XML.PlayerSettings.JUMP_CONSTANT = Mass.gravityForce; XML.PlayerSettings.IN_AIR_JUMP_CONSTANT = XML.PlayerSettings.JUMP_CONSTANT * 1.5f; XML.LevelSettings.TERRAIN_FRICTION = float.Parse(XML.physicsNode.Attributes["friction"].Value); } // Fog properties if (XML.fogNode != null) { XML.LevelSettings.fogDensity = float.Parse(XML.fogNode.Attributes["density"].Value); XML.LevelSettings.zMaxDepth = float.Parse(XML.fogNode.Attributes["depth"].Value); XML.LevelSettings.fogColor[0] = float.Parse(XML.fogNode.Attributes["red"].Value); XML.LevelSettings.fogColor[1] = float.Parse(XML.fogNode.Attributes["green"].Value); XML.LevelSettings.fogColor[2] = float.Parse(XML.fogNode.Attributes["blue"].Value); XML.LevelSettings.fogColor[3] = float.Parse(XML.fogNode.Attributes["alpha"].Value); } } // ============= NEW CLASS =================== // Load Player Screen public struct PlayerInfo { public string name; public string modelPath; public string texPath; public string bumpPath; public float scale; } public static List playerInfo; public static void LoadPlayerIndex(MenuSystem menuSystem) { string playerXMLFile = "_xml/PlayerSettings/PlayerModels.xml"; List modelNames = new List(); playerInfo = new List(); int index = 0; //setup the player scrolling GameMenuImageScroller scroller = (GameMenuImageScroller)menuSystem.playerSetup.GetMenu().GetMenuElement(0); scroller.Clear(); try { // Load physics, music, and fog XmlDocument reader = new XmlDocument(); reader.Load(playerXMLFile); XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode playerNode in allNodes) { if (playerNode.Name == "CharacterModels") { XmlNodeList playerNodes = playerNode.ChildNodes; foreach (XmlNode node in playerNodes) { if (node.Name == "Model") { PlayerInfo player = new PlayerInfo(); player.name = node.Attributes["name"].Value; modelNames.Add(player.name); player.modelPath = node.Attributes["modelFile"].Value; player.texPath = node.Attributes["texFile"].Value; player.bumpPath = node.Attributes["bumpFile"].Value; player.scale = float.Parse(node.Attributes["scale"].Value); playerInfo.Add(player); index++; scroller.AddNew(player.name, ElementalGame.content.Load("_textures/patient" + index), ElementalGame.content.Load("_textures/patient" + index)); } } } } } catch { System.Diagnostics.Debug.WriteLine("Error reading xml"); return; } } // Called from Player public struct PlayerSettings { // Material Properties public static float[] materialDiffuse = { 0.7f, 0.7f, 0.7f, 1.0f }; public static float[] materialSpecular = { 0.1f, 0.1f, 0.1f, 1.0f }; // Rate of translation public static float PLAYER_SPEED_ON_THE_GROUND = 4000.0f; public static float PLAYER_SPEED_IN_THE_AIR = 5500.0f; public static float PLAYER_WALK_SPEED = 5; public static float TERRAIN_MOD_RANGE = 1000.0f; public static int DEFAULT_PLAYER_HEIGHT = 40; public static int MAX_SENSOR_DISTANCE = 50; public static float ATTACK_MANNA_COST = 0.5f; // Cost in manna of using an attack public static float SHIELD_MANNA_COST = 0.2f; public static float JUMP_MANNA_COST = 4.0f; public static float SHIELD_MANNA_GAIN = 5.0f; public static float DIRECT_HEALTH_LOSS = 1.0f; public static float AREA_HEALTH_LOSS = 0.05f; public static float FALLING_HEALTH_LOSS = 1.0f; public static float MAX_VELOCITY = 500.0f; public static int MANNA_INCREMENT_RATE = 1000; // Governs how fast manna regenerates in milliseconds (lower = faster) public static float JUMP_CONSTANT = 600.0f; // Amount of upward force for a jump.. public static float IN_AIR_JUMP_CONSTANT = 1000.0f; // Amount of upward force for an in-air jump.. public static float RATE_OF_FIRE = 500; // Miliseconds before allowing another fully automatic shot to be fired eg: 1000 = 1 sec public static int RESPAWN_DELAY = 5000; // Milliseconds before the player spawns again public static int SPAWN_DONE_DELAY = 5000; // Milliseconds before the player is done spawning (invincible before then) public static float ENEMY_MARKER_MIN_DISTANCE = 750; public static float ENEMY_MARKER_MAX_DISTANCE = 7000; public static float PLAYER_ABSORB_MANNA_COST = 1.0f; public static float PLAYER_ABSORB_HEALTH_GAIN = 0.5f; public static float PARTICLE_ABSORB_MANNA_COST = 1.0f; public static float PARTICLE_ABSORB_MANNA_GAIN = 3.0f; public static float EXPEL_MANNA_COST = 0.2f; public static float EXPEL_HEALTH_LOSS = 0.5f; //this is what it costs even if you don't hit anything public static float ENERGY_BEAM_MANNA_COST = 0.05f; } public static void LoadPlayer() { } } }