Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
PukeParticleSystem.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class PukeParticleSystem : ParticleSystem<PukeParticleSystem.Particle> {
6 public class Particle : Game.Particle {
8
9 public float TimeToLive;
10 }
11
12 public Random m_random = new();
13
15
16 public float m_duration;
17
18 public float m_toGenerate;
19
20 public Vector3 Position { get; set; }
21
22 public Vector3 Direction { get; set; }
23
24 public bool IsStopped { get; set; }
25
26 public PukeParticleSystem(SubsystemTerrain terrain) : base(80) {
27 m_subsystemTerrain = terrain;
28 Texture = ContentManager.Get<Texture2D>("Textures/PukeParticle");
30 }
31
32 public override bool Simulate(float dt) {
33 int num = Terrain.ToCell(Position.X);
34 int num2 = Terrain.ToCell(Position.Y);
35 int num3 = Terrain.ToCell(Position.Z);
36 int x = 0;
37 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num + 1, num2, num3));
38 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num - 1, num2, num3));
39 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 + 1, num3));
40 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 - 1, num3));
41 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 + 1));
42 x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 - 1));
43 Color white = Color.White;
45 white *= num4;
46 white.A = 255;
47 dt = Math.Clamp(dt, 0f, 0.1f);
48 float num5 = MathF.Pow(0.03f, dt);
49 m_duration += dt;
50 if (m_duration > 3.5f) {
51 IsStopped = true;
52 }
53 float num6 = MathUtils.Saturate(1.3f * SimplexNoise.Noise(3f * m_duration + GetHashCode() % 100) - 0.3f);
54 float num7 = 30f * num6;
55 m_toGenerate += num7 * dt;
56 bool flag = false;
57 for (int i = 0; i < Particles.Length; i++) {
58 Particle particle = Particles[i];
59 if (particle.IsActive) {
60 flag = true;
61 particle.TimeToLive -= dt;
62 if (particle.TimeToLive > 0f) {
63 Vector3 position = particle.Position;
64 Vector3 vector = position + particle.Velocity * dt;
65 TerrainRaycastResult? terrainRaycastResult = m_subsystemTerrain.Raycast(
66 position,
67 vector,
68 false,
69 true,
70 (value, _) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable_(value)
71 );
72 if (terrainRaycastResult.HasValue) {
73 Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
74 vector = position;
75 if (plane.Normal.X != 0f) {
76 particle.Velocity *= new Vector3(-0.05f, 0.05f, 0.05f);
77 }
78 if (plane.Normal.Y != 0f) {
79 particle.Velocity *= new Vector3(0.05f, -0.05f, 0.05f);
80 }
81 if (plane.Normal.Z != 0f) {
82 particle.Velocity *= new Vector3(0.05f, 0.05f, -0.05f);
83 }
84 }
85 particle.Position = vector;
86 particle.Velocity.Y += -9.81f * dt;
87 particle.Velocity *= num5;
88 particle.Color *= MathUtils.Saturate(particle.TimeToLive);
89 particle.TextureSlot = (int)(8.99f * MathUtils.Saturate(3f - particle.TimeToLive));
90 }
91 else {
92 particle.IsActive = false;
93 }
94 }
95 else if (!IsStopped
96 && m_toGenerate >= 1f) {
97 Vector3 v = m_random.Vector3(0f, 1f);
98 particle.IsActive = true;
99 particle.Position = Position + 0.05f * v;
100 particle.Color = Color.MultiplyColorOnly(white, m_random.Float(0.7f, 1f));
101 particle.Velocity = MathUtils.Lerp(1f, 2.5f, num6) * Vector3.Normalize(Direction + 0.25f * v);
102 particle.TimeToLive = 3f;
103 particle.Size = new Vector2(0.1f);
104 particle.FlipX = m_random.Bool();
105 particle.FlipY = m_random.Bool();
106 m_toGenerate -= 1f;
107 }
108 }
109 if (IsStopped) {
110 return !flag;
111 }
112 return false;
113 }
114 }
115}
Engine.Vector3 Vector3
static float Saturate(float x)
static int Max(int x1, int x2)
static float Lerp(float x1, float x2, float f)
virtual bool IsCollidable_(int value)
static object Get(Type type, string name)
static readonly float[] LightIntensityByLightValue
ParticleSystem(int particlesCount)
PukeParticleSystem(SubsystemTerrain terrain)
override bool Simulate(float dt)
static float Noise(float x)
static int ExtractContents(int value)
static int ToCell(float x)
static Color White
static Color MultiplyColorOnly(Color c, float s)
Vector3 Normal
定义 Plane.cs:3
static Vector3 Normalize(Vector3 v)