Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System;
  7.  
  8. namespace Breakout
  9. {
  10. public class Main : Game
  11. {
  12. GraphicsDeviceManager graphics;
  13. SpriteBatch spriteBatch;
  14. Color bgColor = new Color(40, 42, 54);
  15. Color paddleColor = new Color(255, 121, 198);
  16. Paddle player;
  17. SpriteFont font;
  18. int xRes = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
  19. int yRes = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
  20. int boop;
  21. Rectangle screenRectangle;
  22.  
  23. public int screenWidth = GraphicsDeviceManager.DefaultBackBufferWidth;
  24. public int screenHeight = GraphicsDeviceManager.DefaultBackBufferHeight;
  25.  
  26. // Framerate averaging
  27. List<int> frames = new List<int>();
  28. int fps;
  29. int averageFramerate;
  30.  
  31. public Main()
  32. {
  33. graphics = new GraphicsDeviceManager(this);
  34. Content.RootDirectory = "Content";
  35. // Place the window in a reasonable spot and make it a reasonable size
  36. this.Window.Position = new Point((screenWidth / 2) - (xRes / 20), (screenHeight / 2) - (yRes / 20));
  37. graphics.PreferredBackBufferWidth = (int)Math.Round(xRes / 1.33);
  38. graphics.PreferredBackBufferHeight = (int)Math.Round(yRes / 1.33);
  39. // Disable fixed timestep
  40. this.IsFixedTimeStep = false;
  41. // Disable Vsync
  42. this.graphics.SynchronizeWithVerticalRetrace = false;
  43. graphics.IsFullScreen = false;
  44. graphics.ApplyChanges();
  45. this.IsMouseVisible = true;
  46.  
  47. screenRectangle = new Rectangle(0, 0, screenWidth, screenHeight);
  48. }
  49.  
  50. protected override void Initialize()
  51. {
  52.  
  53. base.Initialize();
  54. }
  55.  
  56. protected override void LoadContent()
  57. {
  58. spriteBatch = new SpriteBatch(GraphicsDevice);
  59. font = Content.Load<SpriteFont>("Lives");
  60.  
  61. // Create paddle named "player" (speed, lives, width, height, bounds)
  62. player = new Paddle(3, 3, (screenWidth / 5), (screenHeight / 25), screenRectangle);
  63.  
  64. }
  65.  
  66. protected override void UnloadContent()
  67. {
  68. }
  69.  
  70. protected override void Update(GameTime gameTime)
  71. {
  72. if (Keyboard.GetState().IsKeyDown(Keys.Escape))
  73. Exit();
  74. MouseState mouseState = Mouse.GetState();
  75. boop = mouseState.X;
  76.  
  77. // Do stuff while player is alive
  78. while (player.Lives() > 0)
  79. {
  80. Console.WriteLine(player.Lives());
  81. player.Score(1);
  82. player.Die();
  83. }
  84.  
  85. // Average the framerate to make it readable
  86. fps = (int)(Math.Round(1 / gameTime.ElapsedGameTime.TotalSeconds));
  87. frames.Add(fps);
  88. if (frames.Count > 1000)
  89. frames.RemoveAt(0);
  90. averageFramerate = (int)frames.Average();
  91.  
  92. if (mouseState.LeftButton == ButtonState.Pressed) Exit();
  93. System.Diagnostics.Debug.WriteLine("test");
  94. System.Diagnostics.Debug.WriteLine(boop.ToString());
  95. player.Update(gameTime);
  96. base.Update(gameTime);
  97. }
  98.  
  99. protected override void Draw(GameTime gameTime)
  100. {
  101. GraphicsDevice.Clear(bgColor);
  102. spriteBatch.Begin();
  103.  
  104. spriteBatch.DrawString(font, boop.ToString(), new Vector2(100, 100), Color.White);
  105. player.Draw(spriteBatch, player.position, paddleColor);
  106.  
  107. spriteBatch.End();
  108.  
  109. base.Draw(gameTime);
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement