Skip to content

Instantly share code, notes, and snippets.

@Jjagg

Jjagg/Game1.cs Secret

Created December 23, 2015 14:20
Show Gist options
  • Save Jjagg/716924e108a84f0ace19 to your computer and use it in GitHub Desktop.
Save Jjagg/716924e108a84f0ace19 to your computer and use it in GitHub Desktop.
A MonoGame Game object to test the Mercury Particle Engine for MonoGame.
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonoGameMPE.Core;
using MonoGameMPE.Core.Modifiers;
using MonoGameMPE.Core.Modifiers.Container;
using MonoGameMPE.Core.Profiles;
namespace Test
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D _blankTexture;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <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()
{
_blankTexture = new Texture2D(GraphicsDevice, 1, 1);
_blankTexture.SetData(new[] { Color.White });
ParticleInit();
base.Initialize();
}
private ParticleEffect particleEffect;
private SpriteBatchRenderer particleRenderer;
private void ParticleInit()
{
particleRenderer = new SpriteBatchRenderer();
particleEffect = new ParticleEffect
{
Emitters = new[]
{
new Emitter(2000, TimeSpan.FromSeconds(2), Profile.Point())
{
Texture = _blankTexture,
BlendMode = BlendMode.Alpha,
Parameters = new ReleaseParameters
{
Speed = new RangeF(20f, 50f),
Quantity = 3,
},
Modifiers = new IModifier[]
{
new ColourInterpolator2
{
InitialColour = new Colour(0.33f, 0.5f, 0.5f),
FinalColour = new Colour(0f, 0.5f, 0.5f)
},
new RotationModifier
{
RotationRate = 1f
},
new RectContainerModifier
{
Height = 100,
Width = 100,
},
}
}
}
};
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
}
/// <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>
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
particleEffect.Update((float) gameTime.ElapsedGameTime.TotalSeconds);
particleEffect.Trigger(new Vector(300, 200));
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
particleRenderer.Draw(particleEffect, spriteBatch);
base.Draw(gameTime);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment