Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
BlockDebrisParticleSystem.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class BlockDebrisParticleSystem : ParticleSystem<BlockDebrisParticleSystem.Particle> {
6 public class Particle : Game.Particle {
8
9 public float TimeToLive;
10 }
11
12 public Random m_random = new();
13
15
16 public BlockDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot) :
17 base((int)(50f * strength)) {
19 SetBlockDebrisParticle(terrain, position, strength, scale, color, textureSlot);
20 }
21
23 Vector3 position,
24 float strength,
25 float scale,
26 Color color,
27 int textureSlot,
28 Texture2D texture) : base((int)(50f * strength)) {
29 Texture = texture;
30 SetBlockDebrisParticle(terrain, position, strength, scale, color, textureSlot);
31 }
32
33 public void SetBlockDebrisParticle(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot) {
34 m_subsystemTerrain = terrain;
35 int num = Terrain.ToCell(position.X);
36 int num2 = Terrain.ToCell(position.Y);
37 int num3 = Terrain.ToCell(position.Z);
38 int x = 0;
39 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num + 1, num2, num3));
40 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num - 1, num2, num3));
41 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 + 1, num3));
42 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 - 1, num3));
43 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 + 1));
44 x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 - 1));
47 color *= num4;
48 color.A = 255;
49 float num5 = MathF.Sqrt(strength);
50 for (int i = 0; i < Particles.Length; i++) {
51 Particle obj = Particles[i];
52 obj.IsActive = true;
53 Vector3 vector = new(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f));
54 obj.Position = position + strength * 0.45f * vector;
55 obj.Color = Color.MultiplyColorOnly(color, m_random.Float(0.7f, 1f));
56 obj.Size = num5 * scale * new Vector2(m_random.Float(0.05f, 0.06f));
57 obj.TimeToLive = num5 * m_random.Float(1f, 3f);
58 obj.Velocity = num5 * 2f * (vector + new Vector3(m_random.Float(-0.2f, 0.2f), 0.6f, m_random.Float(-0.2f, 0.2f)));
59 obj.TextureSlot = textureSlot % 16 * 2 + m_random.Int(0, 1) + 32 * (textureSlot / 16 * 2 + m_random.Int(0, 1));
60 }
61 }
62
63 public override bool Simulate(float dt) {
64 dt = Math.Clamp(dt, 0f, 0.1f);
65 float num = MathF.Pow(0.1f, dt);
66 bool flag = false;
67 for (int i = 0; i < Particles.Length; i++) {
68 Particle particle = Particles[i];
69 if (!particle.IsActive) {
70 continue;
71 }
72 flag = true;
73 particle.TimeToLive -= dt;
74 if (particle.TimeToLive > 0f) {
75 Vector3 position = particle.Position;
76 Vector3 vector = position + particle.Velocity * dt;
77 TerrainRaycastResult? terrainRaycastResult = m_subsystemTerrain.Raycast(
78 position,
79 vector,
80 false,
81 true,
82 delegate(int value, float _) {
84 return block.IsCollidable && !(block is LeavesBlock);
85 }
86 );
87 if (terrainRaycastResult.HasValue) {
88 Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
89 vector = position;
90 if (plane.Normal.X != 0f) {
91 particle.Velocity *= new Vector3(-0.25f, 0.25f, 0.25f);
92 }
93 if (plane.Normal.Y != 0f) {
94 particle.Velocity *= new Vector3(0.25f, -0.25f, 0.25f);
95 }
96 if (plane.Normal.Z != 0f) {
97 particle.Velocity *= new Vector3(0.25f, 0.25f, -0.25f);
98 }
99 }
100 particle.Position = vector;
101 particle.Velocity.Y += -9.81f * dt;
102 particle.Velocity *= num;
103 particle.Color *= MathUtils.Saturate(particle.TimeToLive);
104 }
105 else {
106 particle.IsActive = false;
107 }
108 }
109 return !flag;
110 }
111 }
112}
Engine.Vector3 Vector3
static float Saturate(float x)
static int Max(int x1, int x2)
BlockDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot, Texture2D texture)
void SetBlockDebrisParticle(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot)
BlockDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot)
static readonly float[] LightIntensityByLightValue
ParticleSystem(int particlesCount)
static int ExtractContents(int value)
virtual int GetCellLight(int x, int y, int z)
static int ToCell(float x)
virtual Subsystem FindSubsystem(Type type, string name, bool throwOnError)
static Color MultiplyColorOnly(Color c, float s)
Vector3 Normal
定义 Plane.cs:3