Advertisement
Guest User

Untitled

a guest
May 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.72 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.  
  77.             graphics.ApplyChanges();
  78.  
  79.             base.Initialize();
  80.         }
  81.  
  82.         // The aspect ratio determines how to scale 3d to 2d projection.
  83.         // This is a texture we can render.
  84.         Texture2D background;
  85.         Texture2D spriteBack;
  86.         Texture2D spriteMiddle;
  87.         Texture2D spriteFront;
  88.  
  89.         Vector2 spritePosition = Vector2.Zero;
  90.  
  91.         protected override void LoadContent()
  92.         {          
  93.             // Create a new SpriteBatch, which can be used to draw textures.
  94.             spriteBatch = new SpriteBatch(GraphicsDevice);
  95.  
  96.             background = Content.Load<Texture2D>("Textures/xna-light");
  97.             spriteBack = Content.Load<Texture2D>("Textures/xna-spriteBack");
  98.             spriteMiddle = Content.Load<Texture2D>("Textures/xna-spriteMiddle");
  99.             spriteFront = Content.Load<Texture2D>("Textures/xna-spriteFront");
  100.  
  101.             particleEffect = Content.Load<ParticleEffect>("mercury");
  102.             particleEffect.LoadContent(Content);
  103.             particleEffect.Initialise();
  104.             particleRenderer.LoadContent(Content);
  105.  
  106.             // FPS-font
  107.             _spr_font = Content.Load<SpriteFont>("kootenay");
  108.  
  109.             Viewport viewport = graphics.GraphicsDevice.Viewport;
  110.         }
  111.  
  112.         /// <summary>
  113.         /// UnloadContent will be called once per game and is the place to unload
  114.         /// all content.
  115.         /// </summary>
  116.         ///
  117.         protected override void UnloadContent()
  118.         {
  119.             // TODO: Unload any non ContentManager content here
  120.         }
  121.  
  122.         /// <summary>
  123.         /// Allows the game to run logic such as updating the world,
  124.         /// checking for collisions, gathering input, and playing audio.
  125.         /// </summary>
  126.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  127.  
  128.         int origoH;
  129.         int origoW;
  130.  
  131.         protected override void Update(GameTime gameTime)
  132.         {
  133.             // Update
  134.             _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
  135.  
  136.             // 1 Second has passed
  137.             if (_elapsed_time >= 1000.0f)
  138.             {
  139.                 _fps = _total_frames;
  140.                 _total_frames = 0;
  141.                 _elapsed_time = 0;
  142.             }
  143.  
  144.             // Allows the game to exit
  145.             if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit();
  146.  
  147.             if (Keyboard.GetState().IsKeyDown(Keys.Left))
  148.             {
  149.                 origoH = 720;
  150.                 origoW = 1280;
  151.                 Window.BeginScreenDeviceChange(false);
  152.                 Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1280, 720);
  153.                 graphics.ApplyChanges();
  154.             }
  155.  
  156.             if (Keyboard.GetState().IsKeyDown(Keys.Right))
  157.             {
  158.                 origoH = 620;
  159.                 origoW = 1180;
  160.                 Window.BeginScreenDeviceChange(false);
  161.                 Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1180, 620);
  162.                 graphics.ApplyChanges();
  163.             }
  164.  
  165.             if (Keyboard.GetState().IsKeyDown(Keys.Up))
  166.             {
  167.                 graphics.IsFullScreen = true;
  168.                 graphics.ApplyChanges();
  169.             }
  170.  
  171.             if (Keyboard.GetState().IsKeyDown(Keys.Down))
  172.             {
  173.                 graphics.IsFullScreen = false;
  174.                 graphics.ApplyChanges();
  175.             }
  176.  
  177.             if (Keyboard.GetState().IsKeyDown(Keys.A))
  178.             {
  179.                 origoH = 1200;
  180.                 origoW = 1920;
  181.                 Window.BeginScreenDeviceChange(false);
  182.                 Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1920, 1200);
  183.             }
  184.  
  185.             particleEffect.Trigger(new Vector2 { X = origoW/2, Y = origoH/2 });
  186.  
  187.             float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
  188.             particleEffect.Update(deltaSeconds);  
  189.  
  190.             base.Update(gameTime);
  191.  
  192.         }
  193.  
  194.         void UpdateSprite(GameTime gameTime)
  195.         {
  196.  
  197.         }
  198.  
  199.         /// <summary>
  200.         /// This is called when the game should draw itself.
  201.         /// </summary>
  202.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  203.         // Set the position of the model in world space, and set the rotation.
  204.         protected override void Draw(GameTime gameTime)
  205.         {
  206.             // Only update total frames when drawing
  207.             _total_frames++;
  208.             GraphicsDevice.Clear(Color.CornflowerBlue);
  209.  
  210.             graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  211.  
  212.             particleRenderer.RenderEffect(particleEffect);
  213.  
  214.             spriteBatch.Begin();
  215.             spriteBatch.Draw(background, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  216.             spriteBatch.Draw(spriteBack, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  217.             spriteBatch.Draw(spriteMiddle, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  218.             spriteBatch.Draw(spriteFront, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
  219.  
  220.             spriteBatch.DrawString(_spr_font, string.Format("FPS={0}", _fps), new Vector2(10.0f, 20.0f), Color.White);
  221.  
  222.  
  223.             spriteBatch.End();
  224.  
  225.            
  226.  
  227.             base.Draw(gameTime);
  228.  
  229.         }
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement