Game1.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5. using Tutorial029.Misc;
  6. using Tutorial029.Models;
  7. using Tutorial029.States;
  8. namespace Tutorial029
  9. {
  10. /// <summary>
  11. /// This is the main type for your game.
  12. /// </summary>
  13. public class Game1 : Game
  14. {
  15. GraphicsDeviceManager graphics;
  16. SpriteBatch spriteBatch;
  17. public static int ScreenWidth = 1280;
  18. public static int ScreenHeight = 720;
  19. private GameModel _gameModel;
  20. private LevelSelectionState _state;
  21. public Game1()
  22. {
  23. graphics = new GraphicsDeviceManager(this);
  24. Content.RootDirectory = "Content";
  25. }
  26. /// <summary>
  27. /// Allows the game to perform any initialization it needs to before starting to run.
  28. /// This is where it can query for any required services and load any non-graphic
  29. /// related content. Calling base.Initialize will enumerate through any components
  30. /// and initialize them as well.
  31. /// </summary>
  32. protected override void Initialize()
  33. {
  34. graphics.PreferredBackBufferWidth = ScreenWidth;
  35. graphics.PreferredBackBufferHeight = ScreenHeight;
  36. graphics.ApplyChanges();
  37. IsMouseVisible = true;
  38. base.Initialize();
  39. }
  40. /// <summary>
  41. /// LoadContent will be called once per game and is the place to load
  42. /// all of your content.
  43. /// </summary>
  44. protected override void LoadContent()
  45. {
  46. // Create a new SpriteBatch, which can be used to draw textures.
  47. spriteBatch = new SpriteBatch(GraphicsDevice);
  48. _gameModel = new GameModel()
  49. {
  50. ContentManger = Content,
  51. GraphicsDeviceManager = graphics,
  52. SpriteBatch = spriteBatch,
  53. };
  54. _state = new LevelSelectionState(_gameModel);
  55. }
  56. /// <summary>
  57. /// UnloadContent will be called once per game and is the place to unload
  58. /// game-specific content.
  59. /// </summary>
  60. protected override void UnloadContent()
  61. {
  62. // TODO: Unload any non ContentManager content here
  63. }
  64. /// <summary>
  65. /// Allows the game to run logic such as updating the world,
  66. /// checking for collisions, gathering input, and playing audio.
  67. /// </summary>
  68. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  69. protected override void Update(GameTime gameTime)
  70. {
  71. _state.Update(gameTime);
  72. base.Update(gameTime);
  73. }
  74. /// <summary>
  75. /// This is called when the game should draw itself.
  76. /// </summary>
  77. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  78. protected override void Draw(GameTime gameTime)
  79. {
  80. GraphicsDevice.Clear(Color.CornflowerBlue);
  81. _state.Draw(gameTime);
  82. base.Draw(gameTime);
  83. }
  84. }
  85. }