RolePlayingGame.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //-----------------------------------------------------------------------------
  2. // RolePlayingGame.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.IO;
  9. using Microsoft.Xna.Framework;
  10. using Microsoft.Xna.Framework.Audio;
  11. using Microsoft.Xna.Framework.Content;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using Microsoft.Xna.Framework.Input;
  14. using RolePlaying.Data;
  15. namespace RolePlaying
  16. {
  17. /// <summary>
  18. /// The Game object for the Role-Playing Game starter kit.
  19. /// </summary>
  20. public class RolePlayingGame : Game
  21. {
  22. GraphicsDeviceManager graphicsDeviceManager;
  23. ScreenManager screenManager;
  24. /// <summary>
  25. /// Indicates if the game is running on a mobile platform.
  26. /// </summary>
  27. public readonly static bool IsMobile = OperatingSystem.IsAndroid() || OperatingSystem.IsIOS();
  28. /// <summary>
  29. /// Indicates if the game is running on a desktop platform.
  30. /// </summary>
  31. public readonly static bool IsDesktop = OperatingSystem.IsMacOS() || OperatingSystem.IsLinux() || OperatingSystem.IsWindows();
  32. /// <summary>
  33. /// Create a new RolePlayingGame object.
  34. /// </summary>
  35. public RolePlayingGame()
  36. {
  37. // initialize the graphics system
  38. graphicsDeviceManager = new GraphicsDeviceManager(this);
  39. graphicsDeviceManager.PreferredBackBufferWidth = Session.BACK_BUFFER_WIDTH;
  40. graphicsDeviceManager.PreferredBackBufferHeight = Session.BACK_BUFFER_HEIGHT;
  41. if (IsMobile)
  42. {
  43. graphicsDeviceManager.IsFullScreen = true;
  44. IsMouseVisible = false;
  45. }
  46. else if (IsDesktop)
  47. {
  48. graphicsDeviceManager.IsFullScreen = false;
  49. IsMouseVisible = true;
  50. }
  51. else
  52. {
  53. throw new PlatformNotSupportedException();
  54. }
  55. // configure the content manager
  56. Content.RootDirectory = "Content";
  57. // Configure screen orientations.
  58. graphicsDeviceManager.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
  59. // add a gamer-services component, which is required for the storage APIs
  60. // TODO: GamerServicesComponent was XNA-specific and not available in MonoGame
  61. // Components.Add(new GamerServicesComponent(this));
  62. // add the audio manager
  63. AudioManager.Initialize(this,
  64. Path.Combine("Content", "Audio", "RPGAudio.xgs"),
  65. Path.Combine("Content", "Audio", "Wave Bank.xwb"),
  66. Path.Combine("Content", "Audio", "Sound Bank.xsb"));
  67. // add the screen manager
  68. screenManager = new ScreenManager(this);
  69. Components.Add(screenManager);
  70. }
  71. /// <summary>
  72. /// Allows the game to perform any initialization it needs to
  73. /// before starting to run. This is where it can query for any required
  74. /// services and load any non-graphic related content. Calling base.Initialize
  75. /// will enumerate through any components and initialize them as well.
  76. /// </summary>
  77. protected override void Initialize()
  78. {
  79. InputManager.Initialize();
  80. base.Initialize();
  81. TileEngine.Viewport = new Viewport(0, 0, Session.BACK_BUFFER_WIDTH, Session.BACK_BUFFER_HEIGHT);
  82. screenManager.AddScreen(new MainMenuScreen());
  83. }
  84. /// <summary>
  85. /// LoadContent will be called once per game and is the place to load
  86. /// all of your content.
  87. /// </summary>
  88. protected override void LoadContent()
  89. {
  90. Fonts.LoadContent(Content);
  91. base.LoadContent();
  92. }
  93. /// <summary>
  94. /// UnloadContent will be called once per game and is the place to unload
  95. /// all content.
  96. /// </summary>
  97. protected override void UnloadContent()
  98. {
  99. Fonts.UnloadContent();
  100. base.UnloadContent();
  101. }
  102. /// <summary>
  103. /// Allows the game to run logic such as updating the world,
  104. /// checking for collisions, gathering input, and playing audio.
  105. /// </summary>
  106. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  107. protected override void Update(GameTime gameTime)
  108. {
  109. InputManager.Update();
  110. base.Update(gameTime);
  111. }
  112. /// <summary>
  113. /// This is called when the game should draw itself.
  114. /// </summary>
  115. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  116. protected override void Draw(GameTime gameTime)
  117. {
  118. graphicsDeviceManager.GraphicsDevice.Clear(Color.Transparent);
  119. base.Draw(gameTime);
  120. }
  121. }
  122. }