Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MoonlordDeathDrama.cs
Go to the documentation of this file.
1using System;
7
9
11{
12 public class MoonlordPiece
13 {
15
17
19
21
22 private float _rotation;
23
24 private float _rotationVelocity;
25
26 public bool Dead
27 {
28 get
29 {
30 if (!(_position.Y > (float)(Main.maxTilesY * 16) - 480f) && !(_position.X < 480f))
31 {
32 return _position.X >= (float)(Main.maxTilesX * 16) - 480f;
33 }
34 return true;
35 }
36 }
37
39 {
42 _position = centerPos;
43 _velocity = velocity;
44 _rotation = rot;
46 }
47
48 public void Update()
49 {
50 _velocity.Y += 0.3f;
52 _rotationVelocity *= 0.99f;
54 }
55
56 public void Draw(SpriteBatch sp)
57 {
58 Color light = GetLight();
59 sp.Draw(_texture, _position - Main.screenPosition, null, light, _rotation, _origin, 1f, SpriteEffects.None, 0f);
60 }
61
63 {
64 return playerScreen.Contains(_position.ToPoint());
65 }
66
67 public Color GetLight()
68 {
70 float num = 0f;
71 int num2 = 5;
72 Point point = _position.ToTileCoordinates();
73 for (int i = point.X - num2; i <= point.X + num2; i++)
74 {
75 for (int j = point.Y - num2; j <= point.Y + num2; j++)
76 {
77 zero += Lighting.GetColor(i, j).ToVector3();
78 num += 1f;
79 }
80 }
81 if (num == 0f)
82 {
83 return Color.White;
84 }
85 return new Color(zero / num);
86 }
87 }
88
89 public class MoonlordExplosion
90 {
92
94
96
98
99 private int _frameCounter;
100
101 private int _frameSpeed;
102
103 public bool Dead
104 {
105 get
106 {
107 if (!(_position.Y > (float)(Main.maxTilesY * 16) - 480f) && !(_position.X < 480f) && !(_position.X >= (float)(Main.maxTilesX * 16) - 480f))
108 {
109 return _frameCounter >= _frameSpeed * 7;
110 }
111 return true;
112 }
113 }
114
115 public MoonlordExplosion(Texture2D pieceTexture, Vector2 centerPos, int frameSpeed)
116 {
118 _position = centerPos;
119 _frameSpeed = frameSpeed;
120 _frameCounter = 0;
121 _frame = _texture.Frame(1, 7);
122 _origin = _frame.Size() / 2f;
123 }
124
125 public void Update()
126 {
128 _frame = _texture.Frame(1, 7, 0, _frameCounter / _frameSpeed);
129 }
130
131 public void Draw(SpriteBatch sp)
132 {
133 Color light = GetLight();
134 sp.Draw(_texture, _position - Main.screenPosition, _frame, light, 0f, _origin, 1f, SpriteEffects.None, 0f);
135 }
136
138 {
139 return playerScreen.Contains(_position.ToPoint());
140 }
141
143 {
144 return new Color(255, 255, 255, 127);
145 }
146 }
147
149
151
153
154 private static float whitening;
155
156 private static float requestedLight;
157
158 public static void Update()
159 {
160 for (int i = 0; i < _pieces.Count; i++)
161 {
163 moonlordPiece.Update();
164 if (moonlordPiece.Dead)
165 {
166 _pieces.Remove(moonlordPiece);
167 i--;
168 }
169 }
170 for (int j = 0; j < _explosions.Count; j++)
171 {
173 moonlordExplosion.Update();
174 if (moonlordExplosion.Dead)
175 {
177 j--;
178 }
179 }
180 bool flag = false;
181 for (int k = 0; k < _lightSources.Count; k++)
182 {
183 if (Main.player[Main.myPlayer].Distance(_lightSources[k]) < 2000f)
184 {
185 flag = true;
186 break;
187 }
188 }
189 _lightSources.Clear();
190 if (!flag)
191 {
192 requestedLight = 0f;
193 }
195 {
196 if (Math.Abs(requestedLight - whitening) < 0.02f)
197 {
199 }
200 else
201 {
202 whitening += (float)Math.Sign(requestedLight - whitening) * 0.02f;
203 }
204 }
205 requestedLight = 0f;
206 }
207
208 public static void DrawPieces(SpriteBatch spriteBatch)
209 {
211 for (int i = 0; i < _pieces.Count; i++)
212 {
213 if (_pieces[i].InDrawRange(playerScreen))
214 {
215 _pieces[i].Draw(spriteBatch);
216 }
217 }
218 }
219
220 public static void DrawExplosions(SpriteBatch spriteBatch)
221 {
223 for (int i = 0; i < _explosions.Count; i++)
224 {
225 if (_explosions[i].InDrawRange(playerScreen))
226 {
227 _explosions[i].Draw(spriteBatch);
228 }
229 }
230 }
231
232 public static void DrawWhite(SpriteBatch spriteBatch)
233 {
234 if (whitening != 0f)
235 {
236 Color color = Color.White * whitening;
237 spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle(-2, -2, Main.screenWidth + 4, Main.screenHeight + 4), new Rectangle(0, 0, 1, 1), color);
238 }
239 }
240
242 {
244 Vector2 vector = Vector2.UnitY.RotatedBy(r.NextFloat() * ((float)Math.PI / 2f) - (float)Math.PI / 4f + (float)Math.PI);
245 _pieces.Add(new MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Spine", (AssetRequestMode)1).Value, new Vector2(64f, 150f), MoonlordCoreCenter + new Vector2(0f, 50f), vector * 6f, 0f, r.NextFloat() * 0.1f - 0.05f));
246 vector = Vector2.UnitY.RotatedBy(r.NextFloat() * ((float)Math.PI / 2f) - (float)Math.PI / 4f + (float)Math.PI);
247 _pieces.Add(new MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Shoulder", (AssetRequestMode)1).Value, new Vector2(40f, 120f), MoonlordCoreCenter + new Vector2(50f, -120f), vector * 10f, 0f, r.NextFloat() * 0.1f - 0.05f));
248 vector = Vector2.UnitY.RotatedBy(r.NextFloat() * ((float)Math.PI / 2f) - (float)Math.PI / 4f + (float)Math.PI);
249 _pieces.Add(new MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Torso", (AssetRequestMode)1).Value, new Vector2(192f, 252f), MoonlordCoreCenter, vector * 8f, 0f, r.NextFloat() * 0.1f - 0.05f));
250 vector = Vector2.UnitY.RotatedBy(r.NextFloat() * ((float)Math.PI / 2f) - (float)Math.PI / 4f + (float)Math.PI);
251 _pieces.Add(new MoonlordPiece(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Head", (AssetRequestMode)1).Value, new Vector2(138f, 185f), MoonlordCoreCenter - new Vector2(0f, 200f), vector * 12f, 0f, r.NextFloat() * 0.1f - 0.05f));
252 }
253
254 public static void AddExplosion(Vector2 spot)
255 {
256 _explosions.Add(new MoonlordExplosion(Main.Assets.Request<Texture2D>("Images/Misc/MoonExplosion/Explosion", (AssetRequestMode)1).Value, spot, Main.rand.Next(2, 4)));
257 }
258
259 public static void RequestLight(float light, Vector2 spot)
260 {
261 _lightSources.Add(spot);
262 if (light > 1f)
263 {
264 light = 1f;
265 }
266 if (requestedLight < light)
267 {
268 requestedLight = light;
269 }
270 }
271}
void Draw(Texture2D texture, Vector2 position, Color color)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static double Abs(double value)
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
MoonlordExplosion(Texture2D pieceTexture, Vector2 centerPos, int frameSpeed)
MoonlordPiece(Texture2D pieceTexture, Vector2 textureOrigin, Vector2 centerPos, Vector2 velocity, float rot, float angularVelocity)
static void DrawExplosions(SpriteBatch spriteBatch)
static void DrawPieces(SpriteBatch spriteBatch)
static void ThrowPieces(Vector2 MoonlordCoreCenter, int DramaSeed)
static void DrawWhite(SpriteBatch spriteBatch)
static void RequestLight(float light, Vector2 spot)
static Asset< Texture2D > MagicPixel
static Color GetColor(Point tileCoords)
Definition Lighting.cs:182
static int maxTilesY
Definition Main.cs:1116
static int myPlayer
Definition Main.cs:1801
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static int maxTilesX
Definition Main.cs:1114
static UnifiedRandom rand
Definition Main.cs:1387
static int screenWidth
Definition Main.cs:1719
static IAssetRepository Assets
Definition Main.cs:209
static Player[] player
Definition Main.cs:1803
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604