Game1.cs 2.7 KB

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