Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 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. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13.  
  14. using ProjectMercury;
  15. using ProjectMercury.Emitters;
  16. using ProjectMercury.Modifiers;
  17. using ProjectMercury.Renderers;
  18.  
  19. namespace WindowsGame1
  20. {
  21. /// <summary>
  22. /// This is the main type for your game
  23. /// </summary>
  24.  
  25. public class Game1 : Microsoft.Xna.Framework.Game
  26. {
  27. GraphicsDeviceManager graphics;
  28. SpriteBatch spriteBatch;
  29.  
  30. SpriteFont _spr_font;
  31. int _total_frames = 0;
  32. float _elapsed_time = 0.0f;
  33. int _fps = 0;
  34.  
  35. int screenWidth = 1280;
  36. int screenHeight = 720;
  37.  
  38. ParticleEffect particleEffect;
  39. Renderer particleRenderer;
  40.  
  41. public Game1()
  42. {
  43. graphics = new GraphicsDeviceManager(this);
  44. Content.RootDirectory = "Content";
  45.  
  46. graphics.PreferredBackBufferWidth = screenWidth;
  47. graphics.PreferredBackBufferHeight = screenHeight;
  48. graphics.IsFullScreen = false;
  49.  
  50. this.Window.AllowUserResizing = true;
  51. this.Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged);
  52. Window.Title = "JoMs - XNA Training";
  53.  
  54. particleRenderer = new SpriteBatchRenderer
  55. {
  56. GraphicsDeviceService = graphics
  57. };
  58. }
  59.  
  60. void Window_ClientSizeChanged(object sender, EventArgs e)
  61. {
  62. screenWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
  63. screenHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
  64. }
  65.  
  66. /// <summary>
  67. /// Allows the game to perform any initialization it needs to before starting to run.
  68. /// This is where it can query for any required services and load any non-graphic
  69. /// related content. Calling base.Initialize will enumerate through any components
  70. /// and initialize them as well.
  71. /// </summary>
  72. protected override void Initialize()
  73. {
  74. // TODO: Add your initialization logic here
  75. this.IsFixedTimeStep = false;
  76. graphics.SynchronizeWithVerticalRetrace = false;
  77.  
  78. graphics.ApplyChanges();
  79.  
  80. particleEffect.Initialise();
  81.  
  82. base.Initialize();
  83. }
  84.  
  85. // The aspect ratio determines how to scale 3d to 2d projection.
  86. // This is a texture we can render.
  87. Texture2D background;
  88. Texture2D spriteBack;
  89. Texture2D spriteMiddle;
  90. Texture2D spriteFront;
  91.  
  92. Vector2 spritePosition = Vector2.Zero;
  93.  
  94. protected override void LoadContent()
  95. {
  96. // Create a new SpriteBatch, which can be used to draw textures.
  97. spriteBatch = new SpriteBatch(GraphicsDevice);
  98.  
  99. background = Content.Load<Texture2D>("Textures/xna-light");
  100. spriteBack = Content.Load<Texture2D>("Textures/xna-spriteBack");
  101. spriteMiddle = Content.Load<Texture2D>("Textures/xna-spriteMiddle");
  102. spriteFront = Content.Load<Texture2D>("Textures/xna-spriteFront");
  103.  
  104. particleEffect = this.Content.Load<ParticleEffect>("mercury");
  105. particleRenderer.LoadContent(Content);
  106.  
  107. // FPS-font
  108. _spr_font = Content.Load<SpriteFont>("kootenay");
  109.  
  110. Viewport viewport = graphics.GraphicsDevice.Viewport;
  111. }
  112.  
  113. /// <summary>
  114. /// UnloadContent will be called once per game and is the place to unload
  115. /// all content.
  116. /// </summary>
  117. ///
  118. protected override void UnloadContent()
  119. {
  120. // TODO: Unload any non ContentManager content here
  121. }
  122.  
  123. /// <summary>
  124. /// Allows the game to run logic such as updating the world,
  125. /// checking for collisions, gathering input, and playing audio.
  126. /// </summary>
  127. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  128.  
  129. int origoH;
  130. int origoW;
  131.  
  132. protected override void Update(GameTime gameTime)
  133. {
  134. // Update
  135. _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
  136.  
  137. // 1 Second has passed
  138. if (_elapsed_time >= 1000.0f)
  139. {
  140. _fps = _total_frames;
  141. _total_frames = 0;
  142. _elapsed_time = 0;
  143. }
  144.  
  145. // Allows the game to exit
  146. if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit();
  147.  
  148. if (Keyboard.GetState().IsKeyDown(Keys.Left))
  149. {
  150. origoH = 720;
  151. origoW = 1280;
  152. Window.BeginScreenDeviceChange(false);
  153. Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1280, 720);
  154. graphics.ApplyChanges();
  155. }
  156.  
  157. if (Keyboard.GetState().IsKeyDown(Keys.Right))
  158. {
  159. origoH = 620;
  160. origoW = 1180;
  161. Window.BeginScreenDeviceChange(false);
  162. Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1180, 620);
  163. graphics.ApplyChanges();
  164. }
  165.  
  166. if (Keyboard.GetState().IsKeyDown(Keys.Up))
  167. {
  168. graphics.IsFullScreen = true;
  169. graphics.ApplyChanges();
  170. }
  171.  
  172. if (Keyboard.GetState().IsKeyDown(Keys.Down))
  173. {
  174. graphics.IsFullScreen = false;
  175. graphics.ApplyChanges();
  176. }
  177.  
  178. if (Keyboard.GetState().IsKeyDown(Keys.A))
  179. {
  180. origoH = 1200;
  181. origoW = 1920;
  182. Window.BeginScreenDeviceChange(false);
  183. Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1920, 1200);
  184. }
  185.  
  186. particleEffect.Trigger(new Vector2 { X = 400f, Y = 300f });
  187.  
  188. float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
  189. particleEffect.Update(deltaSeconds);
  190.  
  191. base.Update(gameTime);
  192.  
  193. }
  194.  
  195. void UpdateSprite(GameTime gameTime)
  196. {
  197.  
  198. }
  199.  
  200. /// <summary>
  201. /// This is called when the game should draw itself.
  202. /// </summary>
  203. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  204. // Set the position of the model in world space, and set the rotation.
  205. protected override void Draw(GameTime gameTime)
  206. {
  207. // Only update total frames when drawing
  208. _total_frames++;
  209. GraphicsDevice.Clear(Color.CornflowerBlue);
  210.  
  211. graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  212.  
  213. // TODO: Add your drawing code here
  214.  
  215. particleRenderer.RenderEffect(particleEffect);
  216.  
  217. spriteBatch.Begin();
  218. spriteBatch.Draw(background, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  219. spriteBatch.Draw(spriteBack, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  220. spriteBatch.Draw(spriteMiddle, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  221. spriteBatch.Draw(spriteFront, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  222.  
  223. spriteBatch.DrawString(_spr_font, string.Format("FPS={0}", _fps), new Vector2(10.0f, 20.0f), Color.White);
  224.  
  225.  
  226. spriteBatch.End();
  227.  
  228.  
  229.  
  230. base.Draw(gameTime);
  231.  
  232. }
  233. }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement