Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
HitValueParticleSystem.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class HitValueParticleSystem : ParticleSystem<HitValueParticleSystem.Particle> {
6 public class Particle : Game.Particle {
7 public float TimeToLive;
8
10
12
13 public string Text;
14 }
15
17
18 public HitValueParticleSystem(Vector3 position, Vector3 velocity, Color color, string text) : base(1) {
19 Random random = new();
20 Particle obj = Particles[0];
21 obj.IsActive = true;
22 obj.Position = position;
23 obj.TimeToLive = 0.9f;
24 obj.Velocity = velocity + random.Vector3(0.75f) * new Vector3(1f, 0f, 1f) + 0.5f * Vector3.UnitY;
25 obj.BaseColor = color;
26 obj.Text = text;
27 }
28
29 public override bool Simulate(float dt) {
30 dt = Math.Clamp(dt, 0f, 0.1f);
31 float num = MathF.Pow(0.1f, dt);
32 bool flag = false;
33 for (int i = 0; i < Particles.Length; i++) {
34 Particle particle = Particles[i];
35 if (particle.IsActive) {
36 flag = true;
37 particle.TimeToLive -= dt;
38 if (particle.TimeToLive > 0f) {
39 particle.Velocity += new Vector3(0f, 0.5f, 0f) * dt;
40 particle.Velocity *= num;
41 particle.Position += particle.Velocity * dt;
42 particle.Color = particle.BaseColor * MathUtils.Saturate(2f * particle.TimeToLive);
43 }
44 else {
45 particle.IsActive = false;
46 }
47 }
48 }
49 return !flag;
50 }
51
52 public override void Draw(Camera camera) {
53 if (m_batch == null) {
55 }
56 Vector3 viewDirection = camera.ViewDirection;
57 Vector3 vector = Vector3.Normalize(Vector3.Cross(viewDirection, Vector3.UnitY));
58 Vector3 v = -Vector3.Normalize(Vector3.Cross(vector, viewDirection));
59 for (int i = 0; i < Particles.Length; i++) {
60 Particle particle = Particles[i];
61 if (particle.IsActive) {
62 float num = Vector3.Distance(camera.ViewPosition, particle.Position);
63 float num2 = MathUtils.Saturate(3f * (num - 0.2f));
64 float num3 = MathUtils.Saturate(0.2f * (20f - num));
65 float num4 = num2 * num3;
66 if (num4 > 0f) {
67 float s = 0.006f * MathF.Sqrt(num);
68 Color color = particle.Color * num4;
69 m_batch.QueueText(
70 particle.Text,
71 particle.Position,
72 vector * s,
73 v * s,
74 color,
75 TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter,
77 );
78 }
79 }
80 }
81 }
82 }
83}
Engine.Vector3 Vector3
static readonly DepthStencilState None
FontBatch3D FontBatch(BitmapFont font, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
static float Saturate(float x)
Vector3 ViewPosition
Vector3 ViewDirection
override void Draw(Camera camera)
HitValueParticleSystem(Vector3 position, Vector3 velocity, Color color, string text)
static BitmapFont BitmapFont
ParticleSystem(int particlesCount)
Vector3 Vector3()
PrimitivesRenderer3D PrimitivesRenderer
static readonly Vector2 Zero
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static float Distance(Vector3 v1, Vector3 v2)
static readonly Vector3 UnitY