CatapultGame.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //-----------------------------------------------------------------------------
  2. // CatapultGame.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Audio;
  12. using Microsoft.Xna.Framework.Content;
  13. //using Microsoft.Xna.Framework.GamerServices; // Not available in MonoGame 3.8
  14. using Microsoft.Xna.Framework.Graphics;
  15. using Microsoft.Xna.Framework.Input;
  16. using Microsoft.Xna.Framework.Input.Touch;
  17. using Microsoft.Xna.Framework.Media;
  18. using Microsoft.Xna.Framework.Net;
  19. namespace CatapultGame
  20. {
  21. /// <summary>
  22. /// This is the main type for your game
  23. /// </summary>
  24. public class CatapultGame : Game
  25. {
  26. GraphicsDeviceManager graphicsDeviceManager;
  27. ScreenManager screenManager;
  28. public ScreenManager ScreenManager { get => screenManager; set => screenManager = value; }
  29. // By preloading any assets used by UI rendering, we avoid framerate glitches
  30. // when they suddenly need to be loaded in the middle of a menu transition.
  31. static readonly string[] preloadAssets =
  32. {
  33. "gradient",
  34. "cat",
  35. "chat_ready",
  36. "chat_able",
  37. "chat_talking",
  38. "chat_mute",
  39. };
  40. public CatapultGame()
  41. {
  42. graphicsDeviceManager = new GraphicsDeviceManager(this);
  43. //graphics.SynchronizeWithVerticalRetrace = false;
  44. graphicsDeviceManager.PreferredBackBufferWidth = ScreenManager.BASE_BUFFER_WIDTH;
  45. graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BASE_BUFFER_HEIGHT;
  46. if (UIUtility.IsMobile)
  47. {
  48. graphicsDeviceManager.IsFullScreen = true;
  49. IsMouseVisible = false;
  50. }
  51. else if (UIUtility.IsDesktop)
  52. {
  53. graphicsDeviceManager.IsFullScreen = false;
  54. IsMouseVisible = true;
  55. }
  56. else
  57. {
  58. throw new PlatformNotSupportedException();
  59. }
  60. Content.RootDirectory = "Content";
  61. //Create a new instance of the Screen Manager
  62. screenManager = new ScreenManager(this);
  63. Components.Add(screenManager);
  64. Components.Add(new MessageDisplayComponent(this));
  65. // Components.Add (new GamerServicesComponent (this)); // Not available in MonoGame 3.8
  66. //Add two new screens
  67. screenManager.AddScreen(new BackgroundScreen(), null);
  68. screenManager.AddScreen(new MainMenuScreen(), null);
  69. // Listen for invite notification events.
  70. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted(screenManager, e);
  71. AudioManager.Initialize(this);
  72. }
  73. /// <summary>
  74. /// Allows the game to perform any initialization it needs to before starting to run.
  75. /// This is where it can query for any required services and load any non-graphic
  76. /// related content. Calling base.Initialize will enumerate through any components
  77. /// and initialize them as well.
  78. /// </summary>
  79. protected override void Initialize()
  80. {
  81. base.Initialize();
  82. }
  83. protected override void LoadContent()
  84. {
  85. AudioManager.LoadSounds();
  86. base.LoadContent();
  87. }
  88. }
  89. }