Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SolarSky.cs
Go to the documentation of this file.
1using System;
7
9
10public class SolarSky : CustomSky
11{
12 private struct Meteor
13 {
15
16 public float Depth;
17
18 public int FrameCounter;
19
20 public float Scale;
21
22 public float StartX;
23 }
24
26
28
30
32
33 private bool _isActive;
34
35 private Meteor[] _meteors;
36
37 private float _fadeOpacity;
38
39 public override void OnLoad()
40 {
41 _planetTexture = Main.Assets.Request<Texture2D>("Images/Misc/SolarSky/Planet", (AssetRequestMode)1);
42 _bgTexture = Main.Assets.Request<Texture2D>("Images/Misc/SolarSky/Background", (AssetRequestMode)1);
43 _meteorTexture = Main.Assets.Request<Texture2D>("Images/Misc/SolarSky/Meteor", (AssetRequestMode)1);
44 }
45
46 public override void Update(GameTime gameTime)
47 {
48 if (_isActive)
49 {
50 _fadeOpacity = Math.Min(1f, 0.01f + _fadeOpacity);
51 }
52 else
53 {
54 _fadeOpacity = Math.Max(0f, _fadeOpacity - 0.01f);
55 }
56 float num = 1200f;
57 for (int i = 0; i < _meteors.Length; i++)
58 {
59 _meteors[i].Position.X -= num * (float)gameTime.ElapsedGameTime.TotalSeconds;
60 _meteors[i].Position.Y += num * (float)gameTime.ElapsedGameTime.TotalSeconds;
61 if ((double)_meteors[i].Position.Y > Main.worldSurface * 16.0)
62 {
64 _meteors[i].Position.Y = -10000f;
65 }
66 }
67 }
68
69 public override Color OnTileColor(Color inColor)
70 {
71 return new Color(Vector4.Lerp(inColor.ToVector4(), Vector4.One, _fadeOpacity * 0.5f));
72 }
73
74 public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
75 {
76 if (maxDepth >= float.MaxValue && minDepth < float.MaxValue)
77 {
79 spriteBatch.Draw(_bgTexture.Value, new Rectangle(0, Math.Max(0, (int)((Main.worldSurface * 16.0 - (double)Main.screenPosition.Y - 2400.0) * 0.10000000149011612)), Main.screenWidth, Main.screenHeight), Color.White * Math.Min(1f, (Main.screenPosition.Y - 800f) / 1000f * _fadeOpacity));
80 Vector2 vector = new Vector2(Main.screenWidth >> 1, Main.screenHeight >> 1);
81 Vector2 vector2 = 0.01f * (new Vector2((float)Main.maxTilesX * 8f, (float)Main.worldSurface / 2f) - Main.screenPosition);
82 spriteBatch.Draw(_planetTexture.Value, vector + new Vector2(-200f, -200f) + vector2, null, Color.White * 0.9f * _fadeOpacity, 0f, new Vector2(_planetTexture.Width() >> 1, _planetTexture.Height() >> 1), 1f, SpriteEffects.None, 1f);
83 }
84 int num = -1;
85 int num2 = 0;
86 for (int i = 0; i < _meteors.Length; i++)
87 {
88 float depth = _meteors[i].Depth;
89 if (num == -1 && depth < maxDepth)
90 {
91 num = i;
92 }
93 if (depth <= minDepth)
94 {
95 break;
96 }
97 num2 = i;
98 }
99 if (num == -1)
100 {
101 return;
102 }
103 float num3 = Math.Min(1f, (Main.screenPosition.Y - 1000f) / 1000f);
104 Vector2 vector3 = Main.screenPosition + new Vector2(Main.screenWidth >> 1, Main.screenHeight >> 1);
105 Rectangle rectangle = new Rectangle(-1000, -1000, 4000, 4000);
106 for (int j = num; j < num2; j++)
107 {
108 Vector2 vector4 = new Vector2(1f / _meteors[j].Depth, 0.9f / _meteors[j].Depth);
109 Vector2 position = (_meteors[j].Position - vector3) * vector4 + vector3 - Main.screenPosition;
110 int num4 = _meteors[j].FrameCounter / 3;
111 _meteors[j].FrameCounter = (_meteors[j].FrameCounter + 1) % 12;
112 if (rectangle.Contains((int)position.X, (int)position.Y))
113 {
114 spriteBatch.Draw(_meteorTexture.Value, position, new Rectangle(0, num4 * (_meteorTexture.Height() / 4), _meteorTexture.Width(), _meteorTexture.Height() / 4), Color.White * num3 * _fadeOpacity, 0f, Vector2.Zero, vector4.X * 5f * _meteors[j].Scale, SpriteEffects.None, 0f);
115 }
116 }
117 }
118
119 public override float GetCloudAlpha()
120 {
121 return (1f - _fadeOpacity) * 0.3f + 0.7f;
122 }
123
124 public override void Activate(Vector2 position, params object[] args)
125 {
126 _fadeOpacity = 0.002f;
127 _isActive = true;
128 _meteors = new Meteor[150];
129 for (int i = 0; i < _meteors.Length; i++)
130 {
131 float num = (float)i / (float)_meteors.Length;
132 _meteors[i].Position.X = num * ((float)Main.maxTilesX * 16f) + _random.NextFloat() * 40f - 20f;
133 _meteors[i].Position.Y = _random.NextFloat() * (0f - ((float)Main.worldSurface * 16f + 10000f)) - 10000f;
134 if (_random.Next(3) != 0)
135 {
136 _meteors[i].Depth = _random.NextFloat() * 3f + 1.8f;
137 }
138 else
139 {
140 _meteors[i].Depth = _random.NextFloat() * 5f + 4.8f;
141 }
143 _meteors[i].Scale = _random.NextFloat() * 0.5f + 1f;
145 }
147 }
148
149 private int SortMethod(Meteor meteor1, Meteor meteor2)
150 {
151 return meteor2.Depth.CompareTo(meteor1.Depth);
152 }
153
154 public override void Deactivate(params object[] args)
155 {
156 _isActive = false;
157 }
158
159 public override void Reset()
160 {
161 _isActive = false;
162 }
163
164 public override bool IsActive()
165 {
166 if (!_isActive)
167 {
168 return _fadeOpacity > 0.001f;
169 }
170 return true;
171 }
172}
void Draw(Texture2D texture, Vector2 position, Color color)
static void Sort(Array array)
Definition Array.cs:2329
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
override Color OnTileColor(Color inColor)
Definition SolarSky.cs:69
Asset< Texture2D > _meteorTexture
Definition SolarSky.cs:31
override void Update(GameTime gameTime)
Definition SolarSky.cs:46
int SortMethod(Meteor meteor1, Meteor meteor2)
Definition SolarSky.cs:149
override void Deactivate(params object[] args)
Definition SolarSky.cs:154
Asset< Texture2D > _bgTexture
Definition SolarSky.cs:29
override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
Definition SolarSky.cs:74
override void Activate(Vector2 position, params object[] args)
Definition SolarSky.cs:124
Asset< Texture2D > _planetTexture
Definition SolarSky.cs:27
static Asset< Texture2D > BlackTile
static double worldSurface
Definition Main.cs:1272
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static int maxTilesX
Definition Main.cs:1114
static int screenWidth
Definition Main.cs:1719
static IAssetRepository Assets
Definition Main.cs:209
bool Contains(int x, int y)
Definition Rectangle.cs:92
static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
Definition Vector4.cs:277