Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. #region Using Statements
  2. using System;
  3. using System.Collections.Generic;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Content;
  6. using Microsoft.Xna.Framework.Graphics;
  7. using Microsoft.Xna.Framework.Input;
  8. using Microsoft.Xna.Framework.Storage;
  9. using Microsoft.Xna.Framework.GamerServices;
  10. #endregion
  11.  
  12. namespace PongGame
  13. {
  14. /// <summary>
  15. /// This is the main type for your game
  16. /// </summary>
  17. public class Game1 : Game
  18. {
  19. GraphicsDeviceManager graphics;
  20. SpriteBatch spriteBatch;
  21. Texture2D text;
  22.  
  23. //rektanglar
  24. Rectangle ballRect, paddelLeftRect, paddelRightRect;
  25.  
  26. //mått
  27. int lengtPadelLeft = 150, lengthPadelRight = 150, width = 10;
  28.  
  29. //bollens fart
  30. int ballSpeedX = 2, ballSpeedY = 2;
  31.  
  32. public Game1()
  33. : base()
  34. {
  35. graphics = new GraphicsDeviceManager(this);
  36. Content.RootDirectory = "Content";
  37. }
  38.  
  39. /// <summary>
  40. /// Allows the game to perform any initialization it needs to before starting to run.
  41. /// This is where it can query for any required services and load any non-graphic
  42. /// related content. Calling base.Initialize will enumerate through any components
  43. /// and initialize them as well.
  44. /// </summary>
  45. protected override void Initialize()
  46. {
  47. // TODO: Add your initialization logic here
  48.  
  49. base.Initialize();
  50. }
  51.  
  52. /// <summary>
  53. /// LoadContent will be called once per game and is the place to load
  54. /// all of your content.
  55. /// </summary>
  56. protected override void LoadContent()
  57. {
  58. // Create a new SpriteBatch, which can be used to draw textures.
  59. spriteBatch = new SpriteBatch(GraphicsDevice);
  60.  
  61. text = Content.Load<Texture2D>("pixel");
  62.  
  63. // TODO: use this.Content to load your game content here
  64.  
  65. //laddar Bollen
  66. ballRect = new Rectangle(Window.ClientBounds.Width / 2, Window.ClientBounds.Height / 2, width, width);
  67. }
  68.  
  69. /// <summary>
  70. /// UnloadContent will be called once per game and is the place to unload
  71. /// all content.
  72. /// </summary>
  73. protected override void UnloadContent()
  74. {
  75. // TODO: Unload any non ContentManager content here
  76. }
  77.  
  78. /// <summary>
  79. /// Allows the game to run logic such as updating the world,
  80. /// checking for collisions, gathering input, and playing audio.
  81. /// </summary>
  82. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  83. protected override void Update(GameTime gameTime)
  84. {
  85.  
  86. ballRect.X += ballSpeedX;
  87. ballRect.Y += ballSpeedY;
  88.  
  89. //kontrollera ifall bollen hamnar uppe eller nere
  90. if(ballRect.Y < 0 || ballRect.Y > Window.ClientBounds.Height)
  91. {
  92. ballSpeedY *= -1;
  93. }
  94.  
  95. // TODO: Add your update logic here
  96.  
  97. base.Update(gameTime);
  98. }
  99.  
  100. /// <summary>
  101. /// This is called when the game should draw itself.
  102. /// </summary>
  103. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  104. protected override void Draw(GameTime gameTime)
  105. {
  106. GraphicsDevice.Clear(Color.Black);
  107.  
  108. // TODO: Add your drawing code here
  109.  
  110. spriteBatch.Begin();
  111. spriteBatch.Draw(text, ballRect, Color.GreenYellow);
  112. spriteBatch.End();
  113.  
  114. base.Draw(gameTime);
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement