1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace SpriteBounce1
  13. {
  14. /// <summary>
  15. /// This is the main type for your game
  16. /// </summary>
  17. public class Game1 : Microsoft.Xna.Framework.Game
  18. {
  19. GraphicsDeviceManager graphics;
  20. SpriteBatch spriteBatch;
  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.  
  38. base.Initialize();
  39. }
  40.  
  41. /// <summary>
  42. /// LoadContent will be called once per game and is the place to load
  43. /// all of your content.
  44. /// </summary>
  45. ///
  46.  
  47. Texture2D hkSprite;
  48. Vector2 spritePosition = Vector2.Zero;
  49.  
  50. protected override void LoadContent()
  51. {
  52. // Create a new SpriteBatch, which can be used to draw textures.
  53. spriteBatch = new SpriteBatch(GraphicsDevice);
  54. hkSprite = Content.Load<Texture2D>("hkSprite");
  55.  
  56. // TODO: use this.Content to load your game content here
  57. }
  58.  
  59. /// <summary>
  60. /// UnloadContent will be called once per game and is the place to unload
  61. /// all content.
  62. /// </summary>
  63. protected override void UnloadContent()
  64. {
  65. // TODO: Unload any non ContentManager content here
  66. }
  67.  
  68. /// <summary>
  69. /// Allows the game to run logic such as updating the world,
  70. /// checking for collisions, gathering input, and playing audio.
  71. /// </summary>
  72. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  73. protected override void Update(GameTime gameTime)
  74. {
  75. // Allows the game to exit
  76. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  77. this.Exit();
  78.  
  79. // TODO: Add your update logic here
  80.  
  81. base.Update(gameTime);
  82. }
  83.  
  84. /// <summary>
  85. /// This is called when the game should draw itself.
  86. /// </summary>
  87. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  88. protected override void Draw(GameTime gameTime)
  89. {
  90. GraphicsDevice.Clear(Color.CornflowerBlue);
  91.  
  92. spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
  93. spriteBatch.Draw(hkSprite, spritePosition, Color.Bisque);
  94. spriteBatch.End();
  95.  
  96. // TODO: Add your drawing code here
  97.  
  98. base.Draw(gameTime);
  99. }
  100. }
  101. }
  102.