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