Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MoonLordSky.cs
Go to the documentation of this file.
1using System;
6
8
9public class MoonLordSky : CustomSky
10{
12
13 private bool _isActive;
14
15 private int _moonLordIndex = -1;
16
17 private bool _forPlayer;
18
19 private float _fadeOpacity;
20
21 public MoonLordSky(bool forPlayer)
22 {
23 _forPlayer = forPlayer;
24 }
25
26 public override void OnLoad()
27 {
28 }
29
30 public override void Update(GameTime gameTime)
31 {
32 if (_forPlayer)
33 {
34 if (_isActive)
35 {
36 _fadeOpacity = Math.Min(1f, 0.01f + _fadeOpacity);
37 }
38 else
39 {
40 _fadeOpacity = Math.Max(0f, _fadeOpacity - 0.01f);
41 }
42 }
43 }
44
45 private float GetIntensity()
46 {
47 if (_forPlayer)
48 {
49 return _fadeOpacity;
50 }
52 {
53 float x = 0f;
54 if (_moonLordIndex != -1)
55 {
57 }
58 return 1f - Utils.SmoothStep(3000f, 6000f, x);
59 }
60 return 0f;
61 }
62
63 public override Color OnTileColor(Color inColor)
64 {
65 float intensity = GetIntensity();
66 return new Color(Vector4.Lerp(new Vector4(0.5f, 0.8f, 1f, 1f), inColor.ToVector4(), 1f - intensity));
67 }
68
69 private bool UpdateMoonLordIndex()
70 {
71 if (_moonLordIndex >= 0 && Main.npc[_moonLordIndex].active && Main.npc[_moonLordIndex].type == 398)
72 {
73 return true;
74 }
75 int num = -1;
76 for (int i = 0; i < Main.npc.Length; i++)
77 {
78 if (Main.npc[i].active && Main.npc[i].type == 398)
79 {
80 num = i;
81 break;
82 }
83 }
84 _moonLordIndex = num;
85 return num != -1;
86 }
87
88 public override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
89 {
90 if (maxDepth >= 0f && minDepth < 0f)
91 {
92 float intensity = GetIntensity();
93 spriteBatch.Draw(TextureAssets.BlackTile.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.Black * intensity);
94 }
95 }
96
97 public override float GetCloudAlpha()
98 {
99 return 1f - _fadeOpacity;
100 }
101
102 public override void Activate(Vector2 position, params object[] args)
103 {
104 _isActive = true;
105 if (_forPlayer)
106 {
107 _fadeOpacity = 0.002f;
108 }
109 else
110 {
111 _fadeOpacity = 1f;
112 }
113 }
114
115 public override void Deactivate(params object[] args)
116 {
117 _isActive = false;
118 if (!_forPlayer)
119 {
120 _fadeOpacity = 0f;
121 }
122 }
123
124 public override void Reset()
125 {
126 _isActive = false;
127 _fadeOpacity = 0f;
128 }
129
130 public override bool IsActive()
131 {
132 if (!_isActive)
133 {
134 return _fadeOpacity > 0.001f;
135 }
136 return true;
137 }
138}
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 void Deactivate(params object[] args)
override void Activate(Vector2 position, params object[] args)
override void Draw(SpriteBatch spriteBatch, float minDepth, float maxDepth)
override void Update(GameTime gameTime)
override Color OnTileColor(Color inColor)
static Asset< Texture2D > BlackTile
static int myPlayer
Definition Main.cs:1801
static int screenHeight
Definition Main.cs:1721
static NPC[] npc
Definition Main.cs:1685
static int screenWidth
Definition Main.cs:1719
static Player[] player
Definition Main.cs:1803
static float SmoothStep(float min, float max, float x)
Definition Utils.cs:83
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount)
Definition Vector4.cs:277