Game1.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5. using Tutorial025.Models;
  6. using Tutorial025.Sprites;
  7. namespace Tutorial025
  8. {
  9. /// <summary>
  10. /// This is the main type for your game.
  11. /// </summary>
  12. public class Game1 : Game
  13. {
  14. GraphicsDeviceManager graphics;
  15. SpriteBatch spriteBatch;
  16. private Player _player;
  17. public Game1()
  18. {
  19. graphics = new GraphicsDeviceManager(this);
  20. Content.RootDirectory = "Content";
  21. }
  22. /// <summary>
  23. /// Allows the game to perform any initialization it needs to before starting to run.
  24. /// This is where it can query for any required services and load any non-graphic
  25. /// related content. Calling base.Initialize will enumerate through any components
  26. /// and initialize them as well.
  27. /// </summary>
  28. protected override void Initialize()
  29. {
  30. // TODO: Add your initialization logic here
  31. base.Initialize();
  32. }
  33. /// <summary>
  34. /// LoadContent will be called once per game and is the place to load
  35. /// all of your content.
  36. /// </summary>
  37. protected override void LoadContent()
  38. {
  39. // Create a new SpriteBatch, which can be used to draw textures.
  40. spriteBatch = new SpriteBatch(GraphicsDevice);
  41. var hatAttributes = new Attributes()
  42. {
  43. HealthPoint = 3,
  44. Speed = 0,
  45. };
  46. var jumperAttributes = new Attributes()
  47. {
  48. HealthPoint = 2,
  49. Speed = 2,
  50. };
  51. var trouserAttributes = new Attributes()
  52. {
  53. HealthPoint = 0,
  54. Speed = 3,
  55. };
  56. _player = new Player(Content.Load<Texture2D>("Player/boy"))
  57. {
  58. Position = new Vector2(50, 50),
  59. BaseAttributes = new Attributes()
  60. {
  61. HealthPoint = 10,
  62. Speed = 3,
  63. },
  64. AttributeModifiers = new List<Attributes>()
  65. {
  66. hatAttributes,
  67. jumperAttributes,
  68. trouserAttributes,
  69. },
  70. };
  71. }
  72. /// <summary>
  73. /// UnloadContent will be called once per game and is the place to unload
  74. /// game-specific content.
  75. /// </summary>
  76. protected override void UnloadContent()
  77. {
  78. // TODO: Unload any non ContentManager content here
  79. }
  80. /// <summary>
  81. /// Allows the game to run logic such as updating the world,
  82. /// checking for collisions, gathering input, and playing audio.
  83. /// </summary>
  84. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  85. protected override void Update(GameTime gameTime)
  86. {
  87. _player.Update(gameTime);
  88. base.Update(gameTime);
  89. }
  90. /// <summary>
  91. /// This is called when the game should draw itself.
  92. /// </summary>
  93. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  94. protected override void Draw(GameTime gameTime)
  95. {
  96. GraphicsDevice.Clear(Color.CornflowerBlue);
  97. spriteBatch.Begin();
  98. _player.Draw(gameTime, spriteBatch);
  99. spriteBatch.End();
  100. base.Draw(gameTime);
  101. }
  102. }
  103. }