-
Notifications
You must be signed in to change notification settings - Fork 1
/
FloorCollision.cs
49 lines (40 loc) · 1.53 KB
/
FloorCollision.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Numerics;
using Walgelijk;
using Walgelijk.ParticleSystem;
namespace MadnessMicroactive;
public struct FloorCollision : IParticleModule
{
public bool Disabled { get; set; }
public float BounceFactor = 0.4f;
public float DampeningFactor = 0.9f;
public FloatRange FloorOffset = new FloatRange(-40, 10);
public Hook<Particle> OnCollide = new();
public FloorCollision(float bounceFactor, float dampeningFactor) : this()
{
BounceFactor = bounceFactor;
DampeningFactor = dampeningFactor;
}
public void Process(int index, ref Particle particle, in GameState gameState, ParticlesComponent component, TransformComponent transform)
{
var floor = LevelComponent.FloorLevel + Utilities.Lerp(FloorOffset.Min, FloorOffset.Max, Utilities.Hash(index * 0.52314f));
var isHit = particle.Position.Y <= floor;
if (isHit)
{
particle.Position.Y = floor;
var normal = Vector2.UnitY;
if (particle.Velocity.LengthSquared() > 10000)
{
particle.RotationalVelocity *= -1;
OnCollide.Dispatch(particle);
particle.Velocity = Vector2.Reflect(particle.Velocity, normal) * BounceFactor;
particle.Rotation = Utilities.VectorToAngle(normal) + 90;
particle.RotationalVelocity *= 0.5f;
}
else
{
particle.RotationalVelocity = default;
particle.Velocity = default;
}
}
}
}