Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FancyGolfPredictionLine.cs
Go to the documentation of this file.
1using System;
7
9
11{
12 private class PredictionEntity : Entity
13 {
14 }
15
16 private readonly List<Vector2> _positions;
17
18 private readonly Entity _entity = new PredictionEntity();
19
20 private readonly int _iterations;
21
22 private readonly Color[] _colors = new Color[2]
23 {
25 Color.Gray
26 };
27
28 private readonly BasicDebugDrawer _drawer = new BasicDebugDrawer(Main.instance.GraphicsDevice);
29
30 private float _time;
31
33 {
34 //IL_003a: Unknown result type (might be due to invalid IL or missing references)
35 //IL_0044: Expected O, but got Unknown
36 _positions = new List<Vector2>(iterations * 2 + 1);
38 }
39
41 {
42 bool flag = Main.tileSolid[379];
43 Main.tileSolid[379] = false;
45 _time += 1f / 60f;
46 _entity.position = golfBall.position;
47 _entity.width = golfBall.width;
48 _entity.height = golfBall.height;
51 float angularVelocity = 0f;
52 for (int i = 0; i < _iterations; i++)
53 {
56 }
57 Main.tileSolid[379] = flag;
58 }
59
60 public void Draw(Camera camera, SpriteBatch spriteBatch, float chargeProgress)
61 {
62 _drawer.Begin(camera.GameViewMatrix.TransformationMatrix);
65 Vector2 vector = new Vector2(3.5f, 3.5f);
66 Vector2 origin = value.Size() / 2f;
67 Vector2 vector2 = vector - camera.UnscaledPosition;
68 float num = 0f;
69 float num2 = 0f;
70 for (int i = 0; i < _positions.Count - 1; i++)
71 {
73 if (length != 0f)
74 {
75 for (; num < num2 + length; num += 4f)
76 {
77 float num3 = (num - num2) / length + (float)i;
78 Vector2 position = GetPosition((num - num2) / length + (float)i);
79 Color color = GetColor2(num3);
80 color *= MathHelper.Clamp(2f - 2f * num3 / (float)(_positions.Count - 1), 0f, 1f);
81 spriteBatch.Draw(value, position + vector2, null, color, 0f, origin, GetScale(num), SpriteEffects.None, 0f);
82 }
83 num2 += length;
84 }
85 }
86 _drawer.End();
87 }
88
90 {
91 float num = travelledLength % 200f / 200f;
92 num *= (float)_colors.Length;
93 num -= _time * (float)Math.PI * 1.5f;
94 num %= (float)_colors.Length;
95 if (num < 0f)
96 {
97 num += (float)_colors.Length;
98 }
99 int num2 = (int)Math.Floor(num);
100 int num3 = num2 + 1;
101 num2 = Utils.Clamp(num2 % _colors.Length, 0, _colors.Length - 1);
102 num3 = Utils.Clamp(num3 % _colors.Length, 0, _colors.Length - 1);
103 float amount = num - (float)num2;
105 color.A = 64;
106 return color * 0.6f;
107 }
108
109 private Color GetColor2(float index)
110 {
111 float num = index * 0.5f - _time * (float)Math.PI * 1.5f;
112 int num2 = (int)Math.Floor(num) % _colors.Length;
113 if (num2 < 0)
114 {
115 num2 += _colors.Length;
116 }
117 int num3 = (num2 + 1) % _colors.Length;
118 float amount = num - (float)Math.Floor(num);
120 color.A = 64;
121 return color * 0.6f;
122 }
123
124 private float GetScale(float travelledLength)
125 {
126 return 0.2f + Utils.GetLerpValue(0.8f, 1f, (float)Math.Cos(travelledLength / 50f + _time * -(float)Math.PI) * 0.5f + 0.5f, clamped: true) * 0.15f;
127 }
128
129 private void GetSectionLength(int startIndex, out float length, out float rotation)
130 {
131 int num = startIndex + 1;
132 if (num >= _positions.Count)
133 {
134 num = _positions.Count - 1;
135 }
137 rotation = (_positions[num] - _positions[startIndex]).ToRotation();
138 }
139
141 {
142 int num = (int)Math.Floor(indexProgress);
143 int num2 = num + 1;
144 if (num2 >= _positions.Count)
145 {
146 num2 = _positions.Count - 1;
147 }
148 float amount = indexProgress - (float)num;
150 }
151}
void Draw(Texture2D texture, Vector2 position, Color color)
static float Clamp(float value, float min, float max)
Definition MathHelper.cs:46
static double Cos(double d)
const double PI
Definition Math.cs:16
static double Floor(double d)
Vector2 position
Definition Entity.cs:14
void Update(Entity golfBall, Vector2 impactVelocity, float roughLandResistance)
void GetSectionLength(int startIndex, out float length, out float rotation)
void Draw(Camera camera, SpriteBatch spriteBatch, float chargeProgress)
static void HitGolfBall(Entity entity, Vector2 velocity, float roughLandResistance)
static BallStepResult StepGolfBall(Entity entity, ref float angularVelocity)
static Asset< Texture2D >[] Extra
static Main instance
Definition Main.cs:283
static bool[] tileSolid
Definition Main.cs:1471
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227