Client LuaCsForBarotrauma
Inflate.cs
1 using System;
2 using System.Xml.Linq;
3 using Microsoft.Xna.Framework;
4 
6 {
8  {
9  [Serialize(0.0f, IsPropertySaveable.Yes), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f, DecimalCount = 2, ValueStep = 1)]
10  public override float Frequency { get; set; } = 1;
11  [Serialize(1.0f, IsPropertySaveable.Yes), Editable(MinValueFloat = 0.01f, MaxValueFloat = 10.0f, DecimalCount = 2, ValueStep = 0.1f)]
12  public float Scale { get; set; }
13 
14  public InflateParams(XElement element) : base(element)
15  {
16  }
17  }
18 
20  {
21  public override float Phase
22  {
23  get { return phase; }
24  set
25  {
26  phase = value;
27  //phase %= MathHelper.TwoPi;
28  }
29  }
30  private float phase;
31 
32  private Vector2[,] deformation;
33 
35 
36  public Inflate(XElement element) : base(element, new InflateParams(element))
37  {
38  deformation = new Vector2[Resolution.X, Resolution.Y];
39  for (int x = 0; x < Resolution.X; x++)
40  {
41  float normalizedX = x / (float)(Resolution.X - 1);
42  for (int y = 0; y < Resolution.Y; y++)
43  {
44  float normalizedY = y / (float)(Resolution.X - 1);
45 
46  Vector2 centerDiff = new Vector2(normalizedX - 0.5f, normalizedY - 0.5f);
47  float centerDist = centerDiff.Length() * 2.0f;
48  if (centerDist == 0.0f) continue;
49 
50  deformation[x, y] = (centerDiff / centerDist) * Math.Min(1.0f, centerDist);
51  }
52  }
53 
54  phase = Rand.Range(0.0f, MathHelper.TwoPi);
55  }
56 
57  protected override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
58  {
59  deformation = this.deformation;
60  multiplier = InflateParams.Frequency <= 0.0f ? InflateParams.Scale : (float)(Math.Sin(phase) + 1.0f) / 2.0f * InflateParams.Scale;
61  multiplier *= Params.Strength;
62  }
63 
64  public override void Update(float deltaTime)
65  {
67  {
68  phase += deltaTime * InflateParams.Frequency;
69  phase %= MathHelper.TwoPi;
70  }
71  }
72  }
73 }
override void GetDeformation(out Vector2[,] deformation, out float multiplier, bool inverse)
Definition: Inflate.cs:57
override void Update(float deltaTime)
Definition: Inflate.cs:64