Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaClient/Source/Particles/ParticleEmitter.cs
T
juanjp600 4d225c65f2 Updated to MonoGame 3.6 + Directory refactor
- Barotrauma's projects are in the Barotrauma directory
- All libraries are in the Libraries directory
- MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?)
- NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred
- Removed Content/effects.mgfx as it didn't seem to be used anywhere
- Removed some references to Subsurface directory
- Renamed Launcher2 to Launcher
2017-06-27 09:52:57 -03:00

84 lines
2.7 KiB
C#

using System.Xml.Linq;
using Microsoft.Xna.Framework;
using FarseerPhysics;
using System;
namespace Barotrauma.Particles
{
class ParticleEmitterPrefab
{
public readonly string Name;
public readonly ParticlePrefab particlePrefab;
public readonly float AngleMin, AngleMax;
public readonly float VelocityMin, VelocityMax;
public readonly float ScaleMin, ScaleMax;
public readonly float ParticleAmount;
public ParticleEmitterPrefab(XElement element)
{
Name = element.Name.ToString();
particlePrefab = GameMain.ParticleManager.FindPrefab(ToolBox.GetAttributeString(element, "particle", ""));
if (element.Attribute("startrotation") == null)
{
AngleMin = ToolBox.GetAttributeFloat(element, "anglemin", 0.0f);
AngleMax = ToolBox.GetAttributeFloat(element, "anglemax", 0.0f);
}
else
{
AngleMin = ToolBox.GetAttributeFloat(element, "angle", 0.0f);
AngleMax = AngleMin;
}
AngleMin = MathHelper.ToRadians(AngleMin);
AngleMax = MathHelper.ToRadians(AngleMax);
if (element.Attribute("scalemin")==null)
{
ScaleMin = 1.0f;
ScaleMax = 1.0f;
}
else
{
ScaleMin = ToolBox.GetAttributeFloat(element,"scalemin",1.0f);
ScaleMax = Math.Max(ScaleMin, ToolBox.GetAttributeFloat(element, "scalemax", 1.0f));
}
if (element.Attribute("velocity") == null)
{
VelocityMin = ToolBox.GetAttributeFloat(element, "velocitymin", 0.0f);
VelocityMax = ToolBox.GetAttributeFloat(element, "velocitymax", 0.0f);
}
else
{
VelocityMin = ToolBox.GetAttributeFloat(element, "velocity", 0.0f);
VelocityMax = VelocityMin;
}
ParticleAmount = ToolBox.GetAttributeInt(element, "particleamount", 1);
}
public void Emit(Vector2 position, Hull hullGuess = null)
{
for (int i = 0; i<ParticleAmount; i++)
{
float angle = Rand.Range(AngleMin, AngleMax);
Vector2 velocity = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * Rand.Range(VelocityMin, VelocityMax);
var particle = GameMain.ParticleManager.CreateParticle(particlePrefab, position, velocity, 0.0f, hullGuess);
if (particle!=null)
{
particle.Size *= Rand.Range(ScaleMin, ScaleMax);
}
}
}
}
}