Settings.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Settings.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Input;
  15. using System.IO;
  16. using System.Xml.Serialization;
  17. #endregion
  18. namespace Spacewar
  19. {
  20. /// <summary>
  21. /// The Setting class handles loading and saving of global application settings.
  22. /// The normal .Net classes (System.Configuration) for doing this are not available on the CF (and therefore 360)
  23. /// </summary>
  24. public class Settings
  25. {
  26. #region General App Settings
  27. /// <summary>
  28. /// The path to look for all media in
  29. /// </summary>
  30. public string MediaPath = @"";
  31. /// <summary>
  32. /// The name of the window when running in windowed mode
  33. /// </summary>
  34. public string WindowTitle = "Spacewar";
  35. /// <summary>
  36. /// The length of each level in seconds;
  37. /// </summary>
  38. public int LevelTime = 30;
  39. /// <summary>
  40. /// How much maximum thrust to apply
  41. /// </summary>
  42. public float ThrustPower = 100f;
  43. /// <summary>
  44. /// How much friction to apply to slow down the ship
  45. /// </summary>
  46. public float FrictionFactor = .1f;
  47. /// <summary>
  48. /// Maximum speed a ship will accelerate to
  49. /// </summary>
  50. public float MaxSpeed = 200f;
  51. /// <summary>
  52. /// Time ships spend in recovery after destruction
  53. /// </summary>
  54. public float ShipRecoveryTime = 1.6f;
  55. #endregion
  56. #region Sun settings
  57. /// <summary>
  58. /// The position of the sun
  59. /// </summary>
  60. public Vector2 SunPosition = new Vector2(0f, 0f);
  61. /// <summary>
  62. /// How fast items are pulled towards the sun
  63. /// </summary>
  64. public double GravityStrength = 500000.0;
  65. /// <summary>
  66. /// Power defines the fall off of the suns gravity. 2.0 is 1/(n^2) as in normal gravity.
  67. /// Bigger numbers fall off faster.
  68. /// </summary>
  69. public int GravityPower = 2;
  70. /// <summary>
  71. /// Affect the color of the sun shader
  72. /// </summary>
  73. public float ColorDistribution = 3.0f;
  74. /// <summary>
  75. /// Affects the fade of the sun shader
  76. /// </summary>
  77. public float Fade = 4.0f;
  78. /// <summary>
  79. /// Affects the flame speed of the sun shader
  80. /// </summary>
  81. public float FlameSpeed = 0.22f;
  82. /// <summary>
  83. /// Affects the spread of flames of the sun shder
  84. /// </summary>
  85. public float Spread = 0.50f;
  86. /// <summary>
  87. /// Affects the flames of the sun shader
  88. /// </summary>
  89. public float Flamability = 1.74f;
  90. /// <summary>
  91. /// Size of the sun
  92. /// </summary>
  93. public float Size = 70f;
  94. #endregion
  95. #region AsteroidSettings
  96. /// <summary>
  97. /// Realtive Scale of Asteroids
  98. /// </summary>
  99. public float AsteroidScale = .02f;
  100. #endregion
  101. #region BulletSettings
  102. /// <summary>
  103. /// RelativeScale of bullets
  104. /// </summary>
  105. public float BulletScale = .02f;
  106. #endregion
  107. #region Ship settings
  108. /// <summary>
  109. /// Relative scaling of the ships
  110. /// </summary>
  111. public float ShipScale = 0.02f;
  112. /// <summary>
  113. /// Stores settings for the player ships
  114. /// </summary>
  115. public struct PlayerShipInfo
  116. {
  117. /// <summary>
  118. /// The start position of this ship
  119. /// </summary>
  120. public Vector2 StartPosition;
  121. /// <summary>
  122. /// The start angle of this ship
  123. /// </summary>
  124. public double StartAngle;
  125. /// <summary>
  126. /// Makes a new ShipInfo
  127. /// </summary>
  128. /// <param name="startPosition">Start position</param>
  129. /// <param name="startAngle">Start Angle</param>
  130. public PlayerShipInfo(Vector2 startPosition, double startAngle)
  131. {
  132. StartPosition = startPosition;
  133. StartAngle = startAngle;
  134. }
  135. }
  136. /// <summary>
  137. /// Store default information about the ships
  138. /// </summary>
  139. public PlayerShipInfo[] Ships = new PlayerShipInfo[2] {new PlayerShipInfo(new Vector2(-300, 0), 90),
  140. new PlayerShipInfo(new Vector2(300, 0), 90)};
  141. #endregion
  142. #region WeaponParameters
  143. /// <summary>
  144. /// Stores information about weapons
  145. /// </summary>
  146. public struct WeaponInfo
  147. {
  148. /// <summary>
  149. /// Cost of the weapon
  150. /// </summary>
  151. public int Cost;
  152. /// <summary>
  153. /// Nubmer of seconds the projectile lasts for
  154. /// </summary>
  155. public double Lifetime;
  156. /// <summary>
  157. /// Maximum number of ths projectile that can be shot at a time
  158. /// </summary>
  159. public int Max;
  160. /// <summary>
  161. /// How many projectile fired per trigger pull
  162. /// </summary>
  163. public int Burst;
  164. /// <summary>
  165. /// Acceleration of the projectile
  166. /// </summary>
  167. public float Acceleration;
  168. /// <summary>
  169. /// How much damage this bullet does
  170. /// </summary>
  171. public int Damage;
  172. /// <summary>
  173. /// Creates a new weapon
  174. /// </summary>
  175. /// <param name="cost">Cost of the weapon</param>
  176. public WeaponInfo(int cost, double lifetime, int max, int burst, float acceleration, int damage)
  177. {
  178. Cost = cost;
  179. Lifetime = lifetime;
  180. Max = max;
  181. Burst = burst;
  182. Acceleration = acceleration;
  183. Damage = damage;
  184. }
  185. }
  186. /// <summary>
  187. /// Stores default information about the weapons
  188. /// </summary>
  189. public WeaponInfo[] Weapons = new WeaponInfo[]
  190. {
  191. new WeaponInfo(0, 3.0, 5, 1, 0, 1), //Pea
  192. new WeaponInfo(1000, 3.0, 4, 3, 0, 1), //mgun
  193. new WeaponInfo(2000, 3.0, 3, 3, 0, 1), //double mgun
  194. new WeaponInfo(3000, 2.0, 1, 1, 1.0f, 5), //Rocket
  195. new WeaponInfo(4000, 2.0, 3, 1, 0f, 5), //BFG
  196. };
  197. #endregion
  198. #region Backdrop
  199. /// <summary>
  200. /// How fast the 2 backdrops fade between each other
  201. /// </summary>
  202. public float CrossFadeSpeed = 0.2f;
  203. /// <summary>
  204. /// How much the 2 backdrops move
  205. /// </summary>
  206. public float OffsetSpeed = 0.1f;
  207. #endregion
  208. #region Lighting
  209. /// <summary>
  210. /// Store informtion about lighting the scenes
  211. /// </summary>
  212. public struct ShipLighting
  213. {
  214. /// <summary>
  215. /// Ambient component color
  216. /// </summary>
  217. public Vector4 Ambient;
  218. /// <summary>
  219. /// The direction of the directional light
  220. /// </summary>
  221. public Vector4 DirectionalDirection;
  222. /// <summary>
  223. /// The color of the directional light
  224. /// </summary>
  225. public Vector4 DirectionalColor;
  226. /// <summary>
  227. /// The position of the point light
  228. /// </summary>
  229. public Vector4 PointPosition;
  230. /// <summary>
  231. /// The color of the point light
  232. /// </summary>
  233. public Vector4 PointColor;
  234. /// <summary>
  235. /// The fall off of the point light
  236. /// </summary>
  237. public float PointFactor;
  238. /// <summary>
  239. /// Creates a new lighting scheme
  240. /// </summary>
  241. /// <param name="ambient">Ambient color</param>
  242. /// <param name="directionalDirection">Directional light direction</param>
  243. /// <param name="directionalColor">Directional light color</param>
  244. /// <param name="pointPosition">Point light position</param>
  245. /// <param name="pointColor">Point light color</param>
  246. /// <param name="pointFactor">Point light fall off</param>
  247. public ShipLighting(Vector4 ambient, Vector4 directionalDirection, Vector4 directionalColor, Vector4 pointPosition, Vector4 pointColor, float pointFactor)
  248. {
  249. Ambient = ambient;
  250. DirectionalDirection = directionalDirection;
  251. DirectionalColor = directionalColor;
  252. PointPosition = pointPosition;
  253. PointColor = pointColor;
  254. PointFactor = pointFactor;
  255. }
  256. }
  257. /// <summary>
  258. /// Lighting parameters for in game and menu shaders
  259. /// </summary>
  260. public ShipLighting[] ShipLights = new ShipLighting[]
  261. { //0 is in game
  262. new ShipLighting(new Vector4(1f, 1f, 1f, 1.0f),
  263. new Vector4(1f, 1f, 1f, 0f),
  264. new Vector4(.4f, .4f, .8f, 1.0f),
  265. new Vector4(0f, 0f, 0f, 0f),
  266. new Vector4(.8f, .6f, 0f, 1.0f),
  267. .01f),
  268. //1 is menu screens
  269. new ShipLighting(new Vector4(.2f, .2f, .2f, 1.0f),
  270. new Vector4(1f, 1f, 1f, 0f),
  271. new Vector4(.4f, .4f, .8f, 1.0f),
  272. new Vector4(0f, 0f, 0f, 0f),
  273. new Vector4(.8f, .6f, 0f, 1.0f),
  274. .008f),
  275. };
  276. #endregion
  277. #region Keyboard Settings
  278. /// <summary>
  279. /// Keyboard settings for two players
  280. /// Note: not allowing extensibility for more than 2 players
  281. /// </summary>
  282. // player 1
  283. public Keys Player1Start = Keys.LeftControl;
  284. public Keys Player1Back = Keys.LeftShift;
  285. public Keys Player1A = Keys.V;
  286. public Keys Player1B = Keys.G;
  287. public Keys Player1X = Keys.F;
  288. public Keys Player1Y = Keys.T;
  289. public Keys Player1ThumbstickLeftXmin = Keys.A;
  290. public Keys Player1ThumbstickLeftXmax = Keys.D;
  291. public Keys Player1ThumbstickLeftYmin = Keys.S;
  292. public Keys Player1ThumbstickLeftYmax = Keys.W;
  293. public Keys Player1Left = Keys.A;
  294. public Keys Player1Right = Keys.D;
  295. public Keys Player1Down = Keys.S;
  296. public Keys Player1Up = Keys.W;
  297. public Keys Player1LeftTrigger = Keys.Q;
  298. public Keys Player1RightTrigger = Keys.E;
  299. // player 2
  300. public Keys Player2Start = Keys.RightControl;
  301. public Keys Player2Back = Keys.RightShift;
  302. public Keys Player2A = Keys.Home;
  303. public Keys Player2B = Keys.End;
  304. public Keys Player2X = Keys.PageUp;
  305. public Keys Player2Y = Keys.PageDown;
  306. public Keys Player2ThumbstickLeftXmin = Keys.Left;
  307. public Keys Player2ThumbstickLeftXmax = Keys.Right;
  308. public Keys Player2ThumbstickLeftYmin = Keys.Down;
  309. public Keys Player2ThumbstickLeftYmax = Keys.Up;
  310. public Keys Player2Left = Keys.Left;
  311. public Keys Player2Right = Keys.Right;
  312. public Keys Player2Down = Keys.Down;
  313. public Keys Player2Up = Keys.Up;
  314. public Keys Player2LeftTrigger = Keys.Insert;
  315. public Keys Player2RightTrigger = Keys.Delete;
  316. #endregion
  317. #region Load/Save code
  318. /// <summary>
  319. /// Saves the current settings
  320. /// </summary>
  321. /// <param name="filename">The filename to save to</param>
  322. public void Save(string filename)
  323. {
  324. Stream stream = File.Create(filename);
  325. XmlSerializer serializer = new XmlSerializer(typeof(Settings));
  326. serializer.Serialize(stream, this);
  327. stream.Close();
  328. }
  329. /// <summary>
  330. /// Loads settings from a file
  331. /// </summary>
  332. /// <param name="filename">The filename to load</param>
  333. public static Settings Load(string filename)
  334. {
  335. Stream stream = File.OpenRead(filename);
  336. XmlSerializer serializer = new XmlSerializer(typeof(Settings));
  337. return (Settings)serializer.Deserialize(stream);
  338. }
  339. #endregion
  340. }
  341. }