Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PartySky.cs
Go to the documentation of this file.
6
8
9public class PartySky : CustomSky
10{
11 private struct Balloon
12 {
13 private const int MAX_FRAMES_X = 3;
14
15 private const int MAX_FRAMES_Y = 3;
16
17 private const int FRAME_RATE = 14;
18
19 public int Variant;
20
22
24
25 public float Depth;
26
27 public int FrameHeight;
28
29 public int FrameWidth;
30
31 public float Speed;
32
33 public bool Active;
34
35 private int _frameCounter;
36
38 {
39 get
40 {
41 return _texture;
42 }
43 set
44 {
45 _texture = value;
46 FrameWidth = value.Width / 3;
47 FrameHeight = value.Height / 3;
48 }
49 }
50
51 public int Frame
52 {
53 get
54 {
55 return _frameCounter;
56 }
57 set
58 {
59 _frameCounter = value % 42;
60 }
61 }
62
67 }
68
69 public static bool MultipleSkyWorkaroundFix;
70
71 private bool _active;
72
73 private bool _leaving;
74
75 private float _opacity;
76
78
79 private Balloon[] _balloons;
80
82
83 private int _balloonsDrawing;
84
85 public override void OnLoad()
86 {
88 for (int i = 0; i < _textures.Length; i++)
89 {
90 _textures[i] = TextureAssets.Extra[69 + i];
91 }
92 GenerateBalloons(onlyMissing: false);
93 }
94
95 private void GenerateBalloons(bool onlyMissing)
96 {
97 if (!onlyMissing)
98 {
99 _balloons = new Balloon[Main.maxTilesY / 4];
100 }
101 for (int i = 0; i < _balloons.Length; i++)
102 {
103 if (!onlyMissing || !_balloons[i].Active)
104 {
105 int num = (int)((double)Main.screenPosition.Y * 0.7 - (double)Main.screenHeight);
106 int minValue = (int)((double)num - Main.worldSurface * 16.0);
107 _balloons[i].Position = new Vector2(_random.Next(0, Main.maxTilesX) * 16, _random.Next(minValue, num));
108 ResetBalloon(i);
109 _balloons[i].Active = true;
110 }
111 }
113 }
114
115 public void ResetBalloon(int i)
116 {
117 _balloons[i].Depth = (float)i / (float)_balloons.Length * 1.75f + 1.6f;
118 _balloons[i].Speed = -1.5f - 2.5f * (float)_random.NextDouble();
121 if (_random.Next(30) == 0)
122 {
124 }
125 }
126
127 private bool IsNearParty()
128 {
129 if (!(Main.player[Main.myPlayer].townNPCs > 0f))
130 {
131 return Main.SceneMetrics.PartyMonolithCount > 0;
132 }
133 return true;
134 }
135
136 public override void Update(GameTime gameTime)
137 {
139 {
140 return;
141 }
144 {
145 return;
146 }
147 _opacity = Utils.Clamp(_opacity + (float)IsNearParty().ToDirectionInt() * 0.01f, 0f, 1f);
148 for (int i = 0; i < _balloons.Length; i++)
149 {
150 if (!_balloons[i].Active)
151 {
152 continue;
153 }
154 _balloons[i].Frame++;
156 _balloons[i].Position.X += Main.windSpeedCurrent * (3f - _balloons[i].Speed);
157 if (!(_balloons[i].Position.Y < 300f))
158 {
159 continue;
160 }
161 if (!_leaving)
162 {
163 ResetBalloon(i);
164 _balloons[i].Position = new Vector2(_random.Next(0, Main.maxTilesX) * 16, (float)Main.worldSurface * 16f + 1600f);
165 if (_random.Next(30) == 0)
166 {
168 }
169 }
170 else
171 {
172 _balloons[i].Active = false;
174 }
175 }
176 if (_balloonsDrawing == 0)
177 {
178 _active = false;
179 }
180 _active = true;
181 }
182
183 public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
184 {
185 if (Main.gameMenu && _active)
186 {
187 _active = false;
188 _leaving = false;
189 for (int i = 0; i < _balloons.Length; i++)
190 {
191 _balloons[i].Active = false;
192 }
193 }
194 if ((double)Main.screenPosition.Y > Main.worldSurface * 16.0 || Main.gameMenu || _opacity <= 0f)
195 {
196 return;
197 }
198 int num = -1;
199 int num2 = 0;
200 for (int j = 0; j < _balloons.Length; j++)
201 {
202 float depth = _balloons[j].Depth;
203 if (num == -1 && depth < maxDepth)
204 {
205 num = j;
206 }
207 if (depth <= minDepth)
208 {
209 break;
210 }
211 num2 = j;
212 }
213 if (num == -1)
214 {
215 return;
216 }
217 Vector2 vector = Main.screenPosition + new Vector2(Main.screenWidth >> 1, Main.screenHeight >> 1);
218 Rectangle rectangle = new Rectangle(-1000, -1000, 4000, 4000);
219 for (int k = num; k < num2; k++)
220 {
221 if (_balloons[k].Active)
222 {
223 Color color = new Color(Main.ColorOfTheSkies.ToVector4() * 0.9f + new Vector4(0.1f)) * 0.8f;
224 float num3 = 1f;
225 if (_balloons[k].Depth > 3f)
226 {
227 num3 = 0.6f;
228 }
229 else if ((double)_balloons[k].Depth > 2.5)
230 {
231 num3 = 0.7f;
232 }
233 else if (_balloons[k].Depth > 2f)
234 {
235 num3 = 0.8f;
236 }
237 else if ((double)_balloons[k].Depth > 1.5)
238 {
239 num3 = 0.9f;
240 }
241 num3 *= 0.9f;
242 color = new Color((int)((float)(int)color.R * num3), (int)((float)(int)color.G * num3), (int)((float)(int)color.B * num3), (int)((float)(int)color.A * num3));
243 Vector2 vector2 = new Vector2(1f / _balloons[k].Depth, 0.9f / _balloons[k].Depth);
244 Vector2 position = _balloons[k].Position;
245 position = (position - vector) * vector2 + vector - Main.screenPosition;
246 position.X = (position.X + 500f) % 4000f;
247 if (position.X < 0f)
248 {
249 position.X += 4000f;
250 }
251 position.X -= 500f;
252 if (rectangle.Contains((int)position.X, (int)position.Y))
253 {
254 spriteBatch.Draw(_balloons[k].Texture, position, _balloons[k].GetSourceRectangle(), color * _opacity, 0f, Vector2.Zero, vector2.X * 2f, SpriteEffects.None, 0f);
255 }
256 }
257 }
258 }
259
260 public override void Activate(Vector2 position, params object[] args)
261 {
262 if (_active)
263 {
264 _leaving = false;
265 GenerateBalloons(onlyMissing: true);
266 }
267 else
268 {
269 GenerateBalloons(onlyMissing: false);
270 _active = true;
271 _leaving = false;
272 }
273 }
274
275 public override void Deactivate(params object[] args)
276 {
277 _leaving = true;
278 }
279
280 public override bool IsActive()
281 {
282 return _active;
283 }
284
285 public override void Reset()
286 {
287 _active = false;
288 }
289}
void Draw(Texture2D texture, Vector2 position, Color color)
Asset< Texture2D >[] _textures
Definition PartySky.cs:77
void GenerateBalloons(bool onlyMissing)
Definition PartySky.cs:95
override void Update(GameTime gameTime)
Definition PartySky.cs:136
override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
Definition PartySky.cs:183
override void Activate(Vector2 position, params object[] args)
Definition PartySky.cs:260
override void Deactivate(params object[] args)
Definition PartySky.cs:275
static Asset< Texture2D >[] Extra
static Microsoft.Xna.Framework.Color ColorOfTheSkies
Definition Main.cs:2577
static double worldSurface
Definition Main.cs:1272
static int myPlayer
Definition Main.cs:1801
static bool hasFocus
Definition Main.cs:1781
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static int maxTilesX
Definition Main.cs:1114
static int dayRate
Definition Main.cs:746
static int screenWidth
Definition Main.cs:1719
static bool gameMenu
Definition Main.cs:1926
static bool gamePaused
Definition Main.cs:1072
static Player[] player
Definition Main.cs:1803
bool Contains(int x, int y)
Definition Rectangle.cs:92