Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NebulaSky.cs
Go to the documentation of this file.
1using System;
7
9
10public class NebulaSky : CustomSky
11{
12 private struct LightPillar
13 {
15
16 public float Depth;
17 }
18
20
22
24
26
28
30
31 private bool _isActive;
32
33 private float _fadeOpacity;
34
35 public override void OnLoad()
36 {
37 _planetTexture = Main.Assets.Request<Texture2D>("Images/Misc/NebulaSky/Planet", (AssetRequestMode)1);
38 _bgTexture = Main.Assets.Request<Texture2D>("Images/Misc/NebulaSky/Background", (AssetRequestMode)1);
39 _beamTexture = Main.Assets.Request<Texture2D>("Images/Misc/NebulaSky/Beam", (AssetRequestMode)1);
41 for (int i = 0; i < _rockTextures.Length; i++)
42 {
43 _rockTextures[i] = Main.Assets.Request<Texture2D>("Images/Misc/NebulaSky/Rock_" + i, (AssetRequestMode)1);
44 }
45 }
46
47 public override void Update(GameTime gameTime)
48 {
49 if (_isActive)
50 {
51 _fadeOpacity = Math.Min(1f, 0.01f + _fadeOpacity);
52 }
53 else
54 {
55 _fadeOpacity = Math.Max(0f, _fadeOpacity - 0.01f);
56 }
57 }
58
59 public override Color OnTileColor(Color inColor)
60 {
61 return new Color(Vector4.Lerp(inColor.ToVector4(), Vector4.One, _fadeOpacity * 0.5f));
62 }
63
64 public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
65 {
66 if (maxDepth >= float.MaxValue && minDepth < float.MaxValue)
67 {
69 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));
70 Vector2 vector = new Vector2(Main.screenWidth >> 1, Main.screenHeight >> 1);
71 Vector2 vector2 = 0.01f * (new Vector2((float)Main.maxTilesX * 8f, (float)Main.worldSurface / 2f) - Main.screenPosition);
72 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);
73 }
74 int num = -1;
75 int num2 = 0;
76 for (int i = 0; i < _pillars.Length; i++)
77 {
78 float depth = _pillars[i].Depth;
79 if (num == -1 && depth < maxDepth)
80 {
81 num = i;
82 }
83 if (depth <= minDepth)
84 {
85 break;
86 }
87 num2 = i;
88 }
89 if (num == -1)
90 {
91 return;
92 }
93 Vector2 vector3 = Main.screenPosition + new Vector2(Main.screenWidth >> 1, Main.screenHeight >> 1);
94 Rectangle rectangle = new Rectangle(-1000, -1000, 4000, 4000);
95 float num3 = Math.Min(1f, (Main.screenPosition.Y - 1000f) / 1000f);
96 for (int j = num; j < num2; j++)
97 {
98 Vector2 vector4 = new Vector2(1f / _pillars[j].Depth, 0.9f / _pillars[j].Depth);
99 Vector2 position = _pillars[j].Position;
100 position = (position - vector3) * vector4 + vector3 - Main.screenPosition;
101 if (rectangle.Contains((int)position.X, (int)position.Y))
102 {
103 float num4 = vector4.X * 450f;
104 spriteBatch.Draw(_beamTexture.Value, position, null, Color.White * 0.2f * num3 * _fadeOpacity, 0f, Vector2.Zero, new Vector2(num4 / 70f, num4 / 45f), SpriteEffects.None, 0f);
105 int num5 = 0;
106 for (float num6 = 0f; num6 <= 1f; num6 += 0.03f)
107 {
108 float num7 = 1f - (num6 + Main.GlobalTimeWrappedHourly * 0.02f + (float)Math.Sin(j)) % 1f;
109 spriteBatch.Draw(_rockTextures[num5].Value, position + new Vector2((float)Math.Sin(num6 * 1582f) * (num4 * 0.5f) + num4 * 0.5f, num7 * 2000f), null, Color.White * num7 * num3 * _fadeOpacity, num7 * 20f, new Vector2(_rockTextures[num5].Width() >> 1, _rockTextures[num5].Height() >> 1), 0.9f, SpriteEffects.None, 0f);
110 num5 = (num5 + 1) % _rockTextures.Length;
111 }
112 }
113 }
114 }
115
116 public override float GetCloudAlpha()
117 {
118 return (1f - _fadeOpacity) * 0.3f + 0.7f;
119 }
120
121 public override void Activate(Vector2 position, params object[] args)
122 {
123 _fadeOpacity = 0.002f;
124 _isActive = true;
125 _pillars = new LightPillar[40];
126 for (int i = 0; i < _pillars.Length; i++)
127 {
128 _pillars[i].Position.X = (float)i / (float)_pillars.Length * ((float)Main.maxTilesX * 16f + 20000f) + _random.NextFloat() * 40f - 20f - 20000f;
129 _pillars[i].Position.Y = _random.NextFloat() * 200f - 2000f;
130 _pillars[i].Depth = _random.NextFloat() * 8f + 7f;
131 }
133 }
134
135 private int SortMethod(LightPillar pillar1, LightPillar pillar2)
136 {
137 return pillar2.Depth.CompareTo(pillar1.Depth);
138 }
139
140 public override void Deactivate(params object[] args)
141 {
142 _isActive = false;
143 }
144
145 public override void Reset()
146 {
147 _isActive = false;
148 }
149
150 public override bool IsActive()
151 {
152 if (!_isActive)
153 {
154 return _fadeOpacity > 0.001f;
155 }
156 return true;
157 }
158}
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 double Sin(double a)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
Asset< Texture2D >[] _rockTextures
Definition NebulaSky.cs:29
Asset< Texture2D > _planetTexture
Definition NebulaSky.cs:23
override void Deactivate(params object[] args)
Definition NebulaSky.cs:140
override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
Definition NebulaSky.cs:64
int SortMethod(LightPillar pillar1, LightPillar pillar2)
Definition NebulaSky.cs:135
override void Update(GameTime gameTime)
Definition NebulaSky.cs:47
override Color OnTileColor(Color inColor)
Definition NebulaSky.cs:59
override void Activate(Vector2 position, params object[] args)
Definition NebulaSky.cs:121
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