Guest User

Untitled

a guest
Jun 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Audio;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.GamerServices;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Input;
  7. using Microsoft.Xna.Framework.Media;
  8.  
  9. namespace WindowsGame2
  10. {
  11. /// <summary>
  12. /// This is the main type for your game
  13. /// </summary>
  14. public class Game1 : Microsoft.Xna.Framework.Game
  15. {
  16. GraphicsDeviceManager graphics;
  17. SpriteBatch spriteBatch;
  18.  
  19. //Represents the player
  20. Player player;
  21.  
  22. public Game1()
  23. {
  24. graphics = new GraphicsDeviceManager(this);
  25. Content.RootDirectory = "Content";
  26. }
  27.  
  28. /// <summary>
  29. /// Allows the game to perform any initialization it needs to before starting to run.
  30. /// This is where it can query for any required services and load any non-graphic
  31. /// related content. Calling base.Initialize will enumerate through any components
  32. /// and initialize them as well.
  33. /// </summary>
  34. protected override void Initialize()
  35. {
  36. // TODO: Add your initialization logic here
  37. // Initialize the player class
  38. player = new Player();
  39.  
  40. base.Initialize();
  41. }
  42.  
  43. /// <summary>
  44. /// LoadContent will be called once per game and is the place to load
  45. /// all of your content.
  46. /// </summary>
  47. protected override void LoadContent()
  48. {
  49. // Create a new SpriteBatch, which can be used to draw textures.
  50. spriteBatch = new SpriteBatch(GraphicsDevice);
  51.  
  52. // TODO: use this.Content to load your game content here
  53. //Load the player resource
  54. Vector2 playerPosition = new Vector2
  55. (GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y
  56. + GraphicsDevice.Viewport.TitleSafeArea.Height / 2);
  57. player.Initialize(Content.Load<Texture2D>("player"), playerPosition);
  58. }
  59.  
  60. /// <summary>
  61. /// UnloadContent will be called once per game and is the place to unload
  62. /// all content.
  63. /// </summary>
  64. protected override void UnloadContent()
  65. {
  66. // TODO: Unload any non ContentManager content here
  67. }
  68.  
  69. /// <summary>
  70. /// Allows the game to run logic such as updating the world,
  71. /// checking for collisions, gathering input, and playing audio.
  72. /// </summary>
  73. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  74. protected override void Update(GameTime gameTime)
  75. {
  76. // Allows the game to exit
  77. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  78. this.Exit();
  79.  
  80. // TODO: Add your update logic here
  81.  
  82. base.Update(gameTime);
  83. }
  84.  
  85. /// <summary>
  86. /// This is called when the game should draw itself.
  87. /// </summary>
  88. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  89. protected override void Draw(GameTime gameTime)
  90. {
  91. GraphicsDevice.Clear(Color.CornflowerBlue);
  92.  
  93. // TODO: Add your drawing code here
  94. // Start drawning
  95. spriteBatch.Begin();
  96.  
  97. //Draw the player
  98. player.Draw(spriteBatch);
  99.  
  100. //Stop drawing
  101. spriteBatch.End();
  102.  
  103.  
  104.  
  105. base.Draw(gameTime);
  106. }
  107. }
  108. }
Add Comment
Please, Sign In to add comment