Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ DrawStar()

void Terraria.Main.DrawStar ( ref SceneArea sceneArea,
float starOpacity,
Microsoft::Xna::Framework::Color bgColorForStars,
int i,
Star theStar,
bool artificial,
bool foreground = false )
inlineprivate

Definition at line 59868 of file Main.cs.

59869 {
59870 if (theStar == null || theStar.hidden)
59871 {
59872 return;
59873 }
59874 float num = shimmerAlpha;
59876 float num2 = 1f - theStar.fadeIn;
59877 int num3 = (int)((float)(255 - bgColorForStars.R - 100) * theStar.twinkle * num2);
59878 int num4 = (int)((float)(255 - bgColorForStars.G - 100) * theStar.twinkle * num2);
59879 int num5 = (int)((float)(255 - bgColorForStars.B - 100) * theStar.twinkle * num2);
59880 num3 = (num3 + num5 + num4) / 3;
59881 if (num3 <= 0)
59882 {
59883 return;
59884 }
59885 num3 = (int)((double)num3 * 1.4);
59886 if (num3 > 255)
59887 {
59888 num3 = 255;
59889 }
59890 num4 = num3;
59891 num5 = num3;
59892 color.R = (byte)num3;
59893 color.G = (byte)num4;
59894 color.B = (byte)num5;
59895 color *= starOpacity;
59896 if (num > 0f)
59897 {
59899 if (i % 3 == 0)
59900 {
59901 value.G = (byte)((float)(int)color.G * (1f - num * 0f) * theStar.twinkle * theStar.twinkle);
59902 }
59903 else if (i % 3 == 1)
59904 {
59905 value.B = (byte)((float)(int)color.B * (1f - num * 0f) * theStar.twinkle * theStar.twinkle);
59906 }
59907 else if (i % 3 == 2)
59908 {
59909 value.R = (byte)((float)(int)color.R * (1f - num * 0f) * theStar.twinkle * theStar.twinkle);
59910 }
59911 color = Microsoft.Xna.Framework.Color.Lerp(color, value, num);
59912 if (artificial)
59913 {
59914 color *= num;
59915 }
59916 else
59917 {
59918 color *= 1f - num;
59919 }
59920 }
59921 Vector2 vector = new Vector2(theStar.position.X / 1920f, theStar.position.Y / 1200f) * new Vector2(sceneArea.totalWidth, sceneArea.totalHeight) + new Vector2(0f, sceneArea.bgTopY) + sceneArea.SceneLocalScreenPositionOffset;
59922 if (!theStar.falling)
59923 {
59924 if (vector.X < 0f)
59925 {
59926 vector.X += screenWidth;
59927 }
59928 if (vector.X > (float)screenWidth)
59929 {
59930 vector.X -= screenWidth;
59931 }
59932 if (vector.Y < 0f)
59933 {
59934 vector.Y += screenHeight;
59935 }
59936 if (vector.Y > (float)screenHeight)
59937 {
59938 vector.Y -= screenHeight;
59939 }
59940 }
59941 if (foreground)
59942 {
59943 Vector2 value2 = vector / ScreenSize.ToVector2();
59944 float fromMax = 0.35f;
59945 float num6 = Utils.Remap(Vector2.Distance(value2, new Vector2(0.5f, 0.5f)), 0f, fromMax, 0f, 1f);
59946 color *= num6;
59947 Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((vector + screenPosition).ToTileCoordinates());
59948 float num7 = (float)(int)Math.Max(Math.Max(color2.R, color2.G), color2.B) / 255f;
59949 color *= 1f - num7;
59950 }
59952 Vector2 origin = value3.Size() / 2f;
59953 if (theStar.falling)
59954 {
59955 theStar.fadeIn = 0f;
59956 int num8 = theStar.fallTime;
59957 float num9 = 30f;
59958 if ((float)num8 > num9)
59959 {
59960 num8 = (int)num9;
59961 }
59962 for (int j = 1; j < num8; j++)
59963 {
59964 Vector2 vector2 = theStar.fallSpeed * j * 0.4f;
59965 float num10 = theStar.scale * (1f - (float)j * 1f / num9);
59967 _ = theStar.rotation;
59968 color3 *= 1f - (float)j * 1f / num9;
59969 spriteBatch.Draw(value3, vector - vector2, null, color3, theStar.rotation, origin, num10 * theStar.twinkle * ForcedMinimumZoom, SpriteEffects.None, 0f);
59970 }
59971 if (starGame && theStar.fallSpeed.Y > 0f && Vector2.Distance(new Vector2(mouseX, mouseY), vector) < 70f)
59972 {
59973 starsHit++;
59974 theStar.fallSpeed = vector - new Vector2(mouseX, mouseY);
59975 theStar.fallSpeed.Normalize();
59976 theStar.fallSpeed *= 10f;
59977 if (theStar.fallSpeed.Y > 0f)
59978 {
59979 theStar.fallSpeed.Y *= -1f;
59980 }
59983 }
59984 }
59985 spriteBatch.Draw(value3, vector, null, color, theStar.rotation, origin, theStar.scale * theStar.twinkle * ForcedMinimumZoom, SpriteEffects.None, 0f);
59986 }
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< Texture2D >[] Star
static SpriteBatch spriteBatch
Definition Main.cs:974
static bool starGame
Definition Main.cs:2597
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static int starsHit
Definition Main.cs:2599
static Microsoft.Xna.Framework.Point ScreenSize
Definition Main.cs:2925
static int screenWidth
Definition Main.cs:1719
static int mouseY
Definition Main.cs:606
static float shimmerAlpha
Definition Main.cs:1008
static int mouseX
Definition Main.cs:604
static float ForcedMinimumZoom
Definition Main.cs:225
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91

References Microsoft.Xna.Framework.Color.B, Microsoft.Xna.Framework.Vector2.Distance(), Terraria.Main.ForcedMinimumZoom, Microsoft.Xna.Framework.Color.G, Terraria.Lighting.GetColor(), System.Text.RegularExpressions.i, Microsoft.Xna.Framework.Color.Lerp(), System.Math.Max(), Terraria.Main.mouseX, Terraria.Main.mouseY, Terraria.Audio.SoundEngine.PlaySound(), Microsoft.Xna.Framework.Color.R, Terraria.Utils.Remap(), Terraria.Main.screenHeight, Terraria.Main.screenPosition, Terraria.Main.ScreenSize, Terraria.Main.screenWidth, Terraria.Main.shimmerAlpha, Terraria.Main.spriteBatch, Terraria.GameContent.TextureAssets.Star, Terraria.Main.starGame, Terraria.Main.starsHit, System.value, and Microsoft.Xna.Framework.Graphics.Vector2.

Referenced by Terraria.Main.DrawStarsInBackground().