Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- using ProjectMercury;
- using ProjectMercury.Emitters;
- using ProjectMercury.Modifiers;
- using ProjectMercury.Renderers;
- namespace WindowsGame1
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- SpriteFont _spr_font;
- int _total_frames = 0;
- float _elapsed_time = 0.0f;
- int _fps = 0;
- int screenWidth = 1280;
- int screenHeight = 720;
- ParticleEffect particleEffect;
- Renderer particleRenderer;
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- graphics.PreferredBackBufferWidth = screenWidth;
- graphics.PreferredBackBufferHeight = screenHeight;
- graphics.IsFullScreen = false;
- this.Window.AllowUserResizing = true;
- this.Window.ClientSizeChanged += new EventHandler(Window_ClientSizeChanged);
- Window.Title = "JoMs - XNA Training";
- particleRenderer = new SpriteBatchRenderer
- {
- GraphicsDeviceService = graphics
- };
- }
- void Window_ClientSizeChanged(object sender, EventArgs e)
- {
- screenWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
- screenHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;
- }
- /// <summary>
- /// Allows the game to perform any initialization it needs to before starting to run.
- /// This is where it can query for any required services and load any non-graphic
- /// related content. Calling base.Initialize will enumerate through any components
- /// and initialize them as well.
- /// </summary>
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- this.IsFixedTimeStep = false;
- graphics.ApplyChanges();
- base.Initialize();
- }
- // The aspect ratio determines how to scale 3d to 2d projection.
- // This is a texture we can render.
- Texture2D background;
- Texture2D spriteBack;
- Texture2D spriteMiddle;
- Texture2D spriteFront;
- Vector2 spritePosition = Vector2.Zero;
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- background = Content.Load<Texture2D>("Textures/xna-light");
- spriteBack = Content.Load<Texture2D>("Textures/xna-spriteBack");
- spriteMiddle = Content.Load<Texture2D>("Textures/xna-spriteMiddle");
- spriteFront = Content.Load<Texture2D>("Textures/xna-spriteFront");
- particleEffect = Content.Load<ParticleEffect>("mercury");
- particleEffect.LoadContent(Content);
- particleEffect.Initialise();
- particleRenderer.LoadContent(Content);
- // FPS-font
- _spr_font = Content.Load<SpriteFont>("kootenay");
- Viewport viewport = graphics.GraphicsDevice.Viewport;
- }
- /// <summary>
- /// UnloadContent will be called once per game and is the place to unload
- /// all content.
- /// </summary>
- ///
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- /// <summary>
- /// Allows the game to run logic such as updating the world,
- /// checking for collisions, gathering input, and playing audio.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- int origoH;
- int origoW;
- protected override void Update(GameTime gameTime)
- {
- // Update
- _elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
- // 1 Second has passed
- if (_elapsed_time >= 1000.0f)
- {
- _fps = _total_frames;
- _total_frames = 0;
- _elapsed_time = 0;
- }
- // Allows the game to exit
- if (Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit();
- if (Keyboard.GetState().IsKeyDown(Keys.Left))
- {
- origoH = 720;
- origoW = 1280;
- Window.BeginScreenDeviceChange(false);
- Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1280, 720);
- graphics.ApplyChanges();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Right))
- {
- origoH = 620;
- origoW = 1180;
- Window.BeginScreenDeviceChange(false);
- Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1180, 620);
- graphics.ApplyChanges();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Up))
- {
- graphics.IsFullScreen = true;
- graphics.ApplyChanges();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Down))
- {
- graphics.IsFullScreen = false;
- graphics.ApplyChanges();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.A))
- {
- origoH = 1200;
- origoW = 1920;
- Window.BeginScreenDeviceChange(false);
- Window.EndScreenDeviceChange(Window.ScreenDeviceName, 1920, 1200);
- }
- particleEffect.Trigger(new Vector2 { X = origoW/2, Y = origoH/2 });
- float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
- particleEffect.Update(deltaSeconds);
- base.Update(gameTime);
- }
- void UpdateSprite(GameTime gameTime)
- {
- }
- /// <summary>
- /// This is called when the game should draw itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- // Set the position of the model in world space, and set the rotation.
- protected override void Draw(GameTime gameTime)
- {
- // Only update total frames when drawing
- _total_frames++;
- GraphicsDevice.Clear(Color.CornflowerBlue);
- graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
- particleRenderer.RenderEffect(particleEffect);
- spriteBatch.Begin();
- spriteBatch.Draw(background, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
- spriteBatch.Draw(spriteBack, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
- spriteBatch.Draw(spriteMiddle, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
- spriteBatch.Draw(spriteFront, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
- spriteBatch.DrawString(_spr_font, string.Format("FPS={0}", _fps), new Vector2(10.0f, 20.0f), Color.White);
- spriteBatch.End();
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement