From acea7b2e728787a0d83bbf83c8c1f042d2c32e7e Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Mon, 3 Jun 2024 10:15:45 +0800 Subject: + plugins project --- .../Containers/RectangleLoopContainerModifier.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/Containers/RectangleLoopContainerModifier.cs (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/Containers/RectangleLoopContainerModifier.cs') diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/Containers/RectangleLoopContainerModifier.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/Containers/RectangleLoopContainerModifier.cs new file mode 100644 index 0000000..4da6efa --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/Containers/RectangleLoopContainerModifier.cs @@ -0,0 +1,42 @@ +using Microsoft.Xna.Framework; + +namespace MonoGame.Extended.Particles.Modifiers.Containers +{ + public class RectangleLoopContainerModifier : Modifier + { + public int Width { get; set; } + public int Height { get; set; } + + public override unsafe void Update(float elapsedSeconds, ParticleBuffer.ParticleIterator iterator) + { + while (iterator.HasNext) + { + var particle = iterator.Next(); + var left = particle->TriggerPos.X + Width*-0.5f; + var right = particle->TriggerPos.X + Width*0.5f; + var top = particle->TriggerPos.Y + Height*-0.5f; + var bottom = particle->TriggerPos.Y + Height*0.5f; + + var xPos = particle->Position.X; + var yPos = particle->Position.Y; + + if ((int) particle->Position.X < left) + xPos = particle->Position.X + Width; + else + { + if ((int) particle->Position.X > right) + xPos = particle->Position.X - Width; + } + + if ((int) particle->Position.Y < top) + yPos = particle->Position.Y + Height; + else + { + if ((int) particle->Position.Y > bottom) + yPos = particle->Position.Y - Height; + } + particle->Position = new Vector2(xPos, yPos); + } + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0