summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles')
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxFillProfile.cs18
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxProfile.cs31
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxUniformProfile.cs32
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/CircleProfile.cs24
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/LineProfile.cs17
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/PointProfile.cs14
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/Profile.cs68
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/RingProfile.cs32
-rw-r--r--Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/SprayProfile.cs20
9 files changed, 256 insertions, 0 deletions
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxFillProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxFillProfile.cs
new file mode 100644
index 0000000..e363713
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxFillProfile.cs
@@ -0,0 +1,18 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class BoxFillProfile : Profile
+ {
+ public float Width { get; set; }
+ public float Height { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f),
+ Random.NextSingle(Height*-0.5f, Height*0.5f));
+
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxProfile.cs
new file mode 100644
index 0000000..7d31984
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxProfile.cs
@@ -0,0 +1,31 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class BoxProfile : Profile
+ {
+ public float Width { get; set; }
+ public float Height { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ switch (Random.Next(3))
+ {
+ case 0: // Left
+ offset = new Vector2(Width*-0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
+ break;
+ case 1: // Top
+ offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*-0.5f);
+ break;
+ case 2: // Right
+ offset = new Vector2(Width*0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
+ break;
+ default: // Bottom
+ offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*0.5f);
+ break;
+ }
+
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxUniformProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxUniformProfile.cs
new file mode 100644
index 0000000..9f766dc
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/BoxUniformProfile.cs
@@ -0,0 +1,32 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class BoxUniformProfile : Profile
+ {
+ public float Width { get; set; }
+ public float Height { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ var value = Random.Next((int) (2*Width + 2*Height));
+
+ if (value < Width) // Top
+ offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*-0.5f);
+ else
+ {
+ if (value < 2*Width) // Bottom
+ offset = new Vector2(Random.NextSingle(Width*-0.5f, Width*0.5f), Height*0.5f);
+ else
+ {
+ if (value < 2*Width + Height) // Left
+ offset = new Vector2(Width*-0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
+ else // Right
+ offset = new Vector2(Width*0.5f, Random.NextSingle(Height*-0.5f, Height*0.5f));
+ }
+ }
+
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/CircleProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/CircleProfile.cs
new file mode 100644
index 0000000..ef7f11e
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/CircleProfile.cs
@@ -0,0 +1,24 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class CircleProfile : Profile
+ {
+ public float Radius { get; set; }
+ public CircleRadiation Radiate { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ var dist = Random.NextSingle(0f, Radius);
+
+ Random.NextUnitVector(out heading);
+
+ offset = Radiate == CircleRadiation.In
+ ? new Vector2(-heading.X*dist, -heading.Y*dist)
+ : new Vector2(heading.X*dist, heading.Y*dist);
+
+ if (Radiate == CircleRadiation.None)
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/LineProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/LineProfile.cs
new file mode 100644
index 0000000..bea584e
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/LineProfile.cs
@@ -0,0 +1,17 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class LineProfile : Profile
+ {
+ public Vector2 Axis { get; set; }
+ public float Length { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ var vect = Axis*Random.NextSingle(Length*-0.5f, Length*0.5f);
+ offset = new Vector2(vect.X, vect.Y);
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/PointProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/PointProfile.cs
new file mode 100644
index 0000000..04456d3
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/PointProfile.cs
@@ -0,0 +1,14 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class PointProfile : Profile
+ {
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ offset = Vector2.Zero;
+
+ Random.NextUnitVector(out heading);
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/Profile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/Profile.cs
new file mode 100644
index 0000000..bfde371
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/Profile.cs
@@ -0,0 +1,68 @@
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public abstract class Profile
+ {
+ public enum CircleRadiation
+ {
+ None,
+ In,
+ Out
+ }
+
+ protected FastRandom Random { get; } = new FastRandom();
+
+ public abstract void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading);
+
+ public object Clone()
+ {
+ return MemberwiseClone();
+ }
+
+ public static Profile Point()
+ {
+ return new PointProfile();
+ }
+
+ public static Profile Line(Vector2 axis, float length)
+ {
+ return new LineProfile {Axis = axis, Length = length};
+ }
+
+ public static Profile Ring(float radius, CircleRadiation radiate)
+ {
+ return new RingProfile {Radius = radius, Radiate = radiate};
+ }
+
+ public static Profile Box(float width, float height)
+ {
+ return new BoxProfile {Width = width, Height = height};
+ }
+
+ public static Profile BoxFill(float width, float height)
+ {
+ return new BoxFillProfile {Width = width, Height = height};
+ }
+
+ public static Profile BoxUniform(float width, float height)
+ {
+ return new BoxUniformProfile {Width = width, Height = height};
+ }
+
+ public static Profile Circle(float radius, CircleRadiation radiate)
+ {
+ return new CircleProfile {Radius = radius, Radiate = radiate};
+ }
+
+ public static Profile Spray(Vector2 direction, float spread)
+ {
+ return new SprayProfile {Direction = direction, Spread = spread};
+ }
+
+ public override string ToString()
+ {
+ return GetType().ToString();
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/RingProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/RingProfile.cs
new file mode 100644
index 0000000..d5ac2f8
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/RingProfile.cs
@@ -0,0 +1,32 @@
+using System;
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class RingProfile : Profile
+ {
+ public float Radius { get; set; }
+ public CircleRadiation Radiate { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ Random.NextUnitVector(out heading);
+
+ switch (Radiate)
+ {
+ case CircleRadiation.In:
+ offset = new Vector2(-heading.X*Radius, -heading.Y*Radius);
+ break;
+ case CircleRadiation.Out:
+ offset = new Vector2(heading.X*Radius, heading.Y*Radius);
+ break;
+ case CircleRadiation.None:
+ offset = new Vector2(heading.X*Radius, heading.Y*Radius);
+ Random.NextUnitVector(out heading);
+ break;
+ default:
+ throw new ArgumentOutOfRangeException($"{Radiate} is not supported");
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/SprayProfile.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/SprayProfile.cs
new file mode 100644
index 0000000..6259210
--- /dev/null
+++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Profiles/SprayProfile.cs
@@ -0,0 +1,20 @@
+using System;
+using Microsoft.Xna.Framework;
+
+namespace MonoGame.Extended.Particles.Profiles
+{
+ public class SprayProfile : Profile
+ {
+ public Vector2 Direction { get; set; }
+ public float Spread { get; set; }
+
+ public override void GetOffsetAndHeading(out Vector2 offset, out Vector2 heading)
+ {
+ var angle = (float) Math.Atan2(Direction.Y, Direction.X);
+
+ angle = Random.NextSingle(angle - Spread/2f, angle + Spread/2f);
+ offset = Vector2.Zero;
+ heading = new Vector2((float) Math.Cos(angle), (float) Math.Sin(angle));
+ }
+ }
+} \ No newline at end of file