Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ExplosionParticleSystem.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class ExplosionParticleSystem : ParticleSystem<ExplosionParticleSystem.Particle> {
6 public class Particle : Game.Particle {
7 public float Strength;
8 }
9
10 public Dictionary<Point3, Particle> m_particlesByPoint = [];
11
12 public List<Particle> m_inactiveParticles = [];
13
14 public Random m_random = new();
15
16 public const float m_duration = 2.5f;
17
18 public bool m_isEmpty;
19
20 public ExplosionParticleSystem() : base(2000) {
21 Texture = ContentManager.Get<Texture2D>("Textures/FireParticle");
24 }
25
26 public void SetExplosionCell(Point3 point, float strength) {
27 if (!m_particlesByPoint.TryGetValue(point, out Particle value)) {
28 if (m_inactiveParticles.Count > 0) {
29 value = m_inactiveParticles[^1];
30 m_inactiveParticles.RemoveAt(m_inactiveParticles.Count - 1);
31 }
32 else {
33 for (int i = 0; i < 5; i++) {
34 int num = m_random.Int(0, Particles.Length - 1);
35 if (strength > Particles[num].Strength) {
36 value = Particles[num];
37 }
38 }
39 }
40 if (value != null) {
41 m_particlesByPoint.Add(point, value);
42 }
43 }
44 if (value != null) {
45 value.IsActive = true;
46 value.Position = new Vector3(point.X, point.Y, point.Z)
47 + new Vector3(0.5f)
48 + 0.2f * new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f));
49 value.Size = new Vector2(m_random.Float(0.6f, 0.9f));
50 value.Strength = strength;
51 value.Color = Color.White;
52 m_isEmpty = false;
53 }
54 }
55
56 public override bool Simulate(float dt) {
57 if (!m_isEmpty) {
58 m_isEmpty = true;
59 for (int i = 0; i < Particles.Length; i++) {
60 Particle particle = Particles[i];
61 if (particle.IsActive) {
62 m_isEmpty = false;
63 particle.Strength -= dt / m_duration;
64 if (particle.Strength > 0f) {
65 particle.TextureSlot = (int)MathUtils.Min(9f * (1f - particle.Strength) * 0.6f, 8f);
66 particle.Position.Y += 2f * MathUtils.Max(1f - particle.Strength - 0.25f, 0f) * dt;
67 }
68 else {
69 particle.IsActive = false;
70 m_inactiveParticles.Add(particle);
71 }
72 }
73 }
74 }
75 return false;
76 }
77
78 public override void Draw(Camera camera) {
79 if (!m_isEmpty) {
80 base.Draw(camera);
81 }
82 }
83 }
84}
Engine.Vector3 Vector3
static int Min(int x1, int x2)
static int Max(int x1, int x2)
static object Get(Type type, string name)
void SetExplosionCell(Point3 point, float strength)
Dictionary< Point3, Particle > m_particlesByPoint
ParticleSystem(int particlesCount)
static Color White