Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  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 MyGames
  13. {
  14. /// <summary>
  15. /// This is the main type for your game
  16. /// </summary>
  17. public class SpaceInvader : Game
  18. {
  19. private readonly GraphicsDeviceManager graphics_;
  20. private KeyboardState oldKeyboardState_;
  21. private KeyboardState newKeyboardState_;
  22. private SpriteBatch spriteBatch_;
  23. private Ship playerShip_;
  24.  
  25. public SpaceInvader()
  26. {
  27. graphics_ = new GraphicsDeviceManager(this);
  28. Content.RootDirectory = "Content";
  29. // Set device frame rate to 60 fps.
  30. TargetElapsedTime = TimeSpan.FromSeconds(1 / 60.0);
  31. graphics_.PreferredBackBufferWidth = 480;
  32. graphics_.PreferredBackBufferHeight = 268;
  33. }
  34.  
  35. protected override void Initialize()
  36. {
  37. playerShip_ = new Ship(new Vector2(Window.ClientBounds.Width / 2, Window.ClientBounds.Height - 150), new Vector2(10,10));
  38. base.Initialize();
  39. }
  40.  
  41. protected override void LoadContent()
  42. {
  43. // Create a new SpriteBatch, which can be used to draw textures.
  44. spriteBatch_ = new SpriteBatch(GraphicsDevice);
  45. playerShip_.LoadContent(Content);
  46. }
  47.  
  48. protected override void UnloadContent()
  49. {
  50. // TODO: Unload any non ContentManager content here
  51. }
  52.  
  53. protected override void Update(GameTime gameTime)
  54. {
  55. newKeyboardState_ = Keyboard.GetState();
  56. // Allows the game to exit
  57. if (newKeyboardState_.IsKeyDown(Keys.Escape))
  58. Exit();
  59.  
  60. // TODO: Add your update logic here
  61. playerShip_.Update(Window, newKeyboardState_, oldKeyboardState_);
  62.  
  63. base.Update(gameTime);
  64. }
  65.  
  66. protected override void Draw(GameTime gameTime)
  67. {
  68. if (oldKeyboardState_.IsKeyDown(Keys.F) && newKeyboardState_.IsKeyUp(Keys.F))
  69. graphics_.ToggleFullScreen();
  70. graphics_.GraphicsDevice.Clear(Color.CornflowerBlue);
  71. //set rendering back to the back buffer
  72.  
  73. // Draw the sprite.
  74. spriteBatch_.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
  75. playerShip_.Draw(spriteBatch_);
  76. spriteBatch_.End();
  77.  
  78. base.Draw(gameTime);
  79. oldKeyboardState_ = newKeyboardState_;
  80. }
  81. }
  82. }
  83.  
  84. using (SpaceInvader game = new SpaceInvader())
  85. {
  86. game.Run();
  87. }
  88.  
  89. SpaceInvader game = new SpaceInvader();
  90. game.Run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement