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

◆ DrawNPCs()

void Terraria.Main.DrawNPCs ( bool behindTiles = false)
inlineprotected

Definition at line 20810 of file Main.cs.

20811 {
20812 bool flag = false;
20814 for (int num = 199; num >= 0; num--)
20815 {
20816 try
20817 {
20818 if (npc[num].active && npc[num].type > 0 && npc[num].type < NPCID.Count && !npc[num].hide)
20819 {
20820 npc[num].position += npc[num].netOffset;
20821 if (npc[num].behindTiles == behindTiles)
20822 {
20823 if (npc[num].type == 125 || npc[num].type == 126)
20824 {
20825 if (!NPC.IsMechQueenUp && !flag)
20826 {
20827 flag = true;
20828 for (int i = 0; i < 200; i++)
20829 {
20830 if (!npc[i].active || num == i || (npc[i].type != 125 && npc[i].type != 126))
20831 {
20832 continue;
20833 }
20834 float scale = npc[i].scale;
20835 float x = npc[i].Center.X;
20836 float num2 = npc[i].Bottom.Y - (float)npc[i].height * 0.5f * scale;
20837 float x2 = npc[num].Center.X;
20838 float y = npc[num].Bottom.Y - (float)npc[num].height * 0.5f * scale;
20839 Vector2 vector = new Vector2(x2, y);
20840 float num3 = x - vector.X;
20841 float num4 = num2 - vector.Y;
20842 float rotation = (float)Math.Atan2(num4, num3) - 1.57f;
20843 bool flag2 = true;
20844 float num5 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
20845 if (num5 > 2000f)
20846 {
20847 flag2 = false;
20848 }
20849 float num6 = 40f * scale;
20850 while (flag2)
20851 {
20852 num5 = (float)Math.Sqrt(num3 * num3 + num4 * num4);
20853 if (num5 < num6)
20854 {
20855 flag2 = false;
20856 continue;
20857 }
20858 num5 = (float)TextureAssets.Chain12.Height() * scale / num5;
20859 num3 *= num5;
20860 num4 *= num5;
20861 vector.X += num3;
20862 vector.Y += num4;
20863 num3 = x - vector.X;
20864 num4 = num2 - vector.Y;
20865 Microsoft.Xna.Framework.Color color = Lighting.GetColor((int)vector.X / 16, (int)(vector.Y / 16f));
20866 spriteBatch.Draw(TextureAssets.Chain12.Value, new Vector2(vector.X - screenPosition.X, vector.Y - screenPosition.Y), new Microsoft.Xna.Framework.Rectangle(0, 0, TextureAssets.Chain12.Width(), TextureAssets.Chain12.Height()), color, rotation, new Vector2((float)TextureAssets.Chain12.Width() * 0.5f, (float)TextureAssets.Chain12.Height() * 0.5f), scale, SpriteEffects.None, 0f);
20867 }
20868 }
20869 }
20870 }
20871 else if (npc[num].type == 263 && npc[num].aiStyle == 52 && NPC.plantBoss >= 0)
20872 {
20873 Vector2 vector2 = new Vector2(npc[num].position.X + (float)(npc[num].width / 2), npc[num].position.Y + (float)(npc[num].height / 2));
20874 float num7 = npc[NPC.plantBoss].Center.X - vector2.X;
20875 float num8 = npc[NPC.plantBoss].Center.Y - vector2.Y;
20876 float rotation2 = (float)Math.Atan2(num8, num7) - 1.57f;
20877 bool flag3 = true;
20878 while (flag3)
20879 {
20880 int num9 = 16;
20881 int num10 = 32;
20882 float num11 = (float)Math.Sqrt(num7 * num7 + num8 * num8);
20883 if (num11 < (float)num10)
20884 {
20885 num9 = (int)num11 - num10 + num9;
20886 flag3 = false;
20887 }
20888 num11 = (float)num9 / num11;
20889 num7 *= num11;
20890 num8 *= num11;
20891 vector2.X += num7;
20892 vector2.Y += num8;
20893 num7 = npc[NPC.plantBoss].Center.X - vector2.X + npc[NPC.plantBoss].netOffset.X;
20894 num8 = npc[NPC.plantBoss].Center.Y - vector2.Y + npc[NPC.plantBoss].netOffset.Y;
20895 Microsoft.Xna.Framework.Color color2 = Lighting.GetColor((int)vector2.X / 16, (int)(vector2.Y / 16f));
20896 spriteBatch.Draw(TextureAssets.Chain26.Value, new Vector2(vector2.X - screenPosition.X, vector2.Y - screenPosition.Y), new Microsoft.Xna.Framework.Rectangle(0, 0, TextureAssets.Chain26.Width(), num9), color2, rotation2, new Vector2((float)TextureAssets.Chain26.Width() * 0.5f, (float)TextureAssets.Chain26.Height() * 0.5f), 1f, SpriteEffects.None, 0f);
20897 }
20898 }
20899 else if (npc[num].type == 264 && npc[num].aiStyle == 53 && NPC.plantBoss >= 0)
20900 {
20901 int num12 = NPC.plantBoss;
20902 if (npc[num].ai[3] > 0f)
20903 {
20904 num12 = (int)npc[num].ai[3] - 1;
20905 }
20906 Vector2 vector3 = new Vector2(npc[num].position.X + (float)(npc[num].width / 2), npc[num].position.Y + (float)(npc[num].height / 2));
20907 float num13 = npc[num12].Center.X - vector3.X;
20908 float num14 = npc[num12].Center.Y - vector3.Y;
20909 float rotation3 = (float)Math.Atan2(num14, num13) - 1.57f;
20910 bool flag4 = true;
20911 while (flag4)
20912 {
20913 int num15 = 16;
20914 int num16 = 32;
20915 float num17 = (float)Math.Sqrt(num13 * num13 + num14 * num14);
20916 if (num17 < (float)num16)
20917 {
20918 num15 = (int)num17 - num16 + num15;
20919 flag4 = false;
20920 }
20921 num17 = (float)num15 / num17;
20922 num13 *= num17;
20923 num14 *= num17;
20924 vector3.X += num13;
20925 vector3.Y += num14;
20926 num13 = npc[num12].Center.X - vector3.X + npc[num12].netOffset.X;
20927 num14 = npc[num12].Center.Y - vector3.Y + npc[num12].netOffset.Y;
20928 Microsoft.Xna.Framework.Color color3 = Lighting.GetColor((int)vector3.X / 16, (int)(vector3.Y / 16f));
20929 spriteBatch.Draw(TextureAssets.Chain27.Value, new Vector2(vector3.X - screenPosition.X, vector3.Y - screenPosition.Y), new Microsoft.Xna.Framework.Rectangle(0, 0, TextureAssets.Chain27.Width(), num15), color3, rotation3, new Vector2((float)TextureAssets.Chain27.Width() * 0.5f, (float)TextureAssets.Chain27.Height() * 0.5f), 1f, SpriteEffects.None, 0f);
20930 }
20931 }
20932 if (NPCID.Sets.MustAlwaysDraw[npc[num].type] || rectangle.Intersects(new Microsoft.Xna.Framework.Rectangle((int)npc[num].position.X, (int)npc[num].position.Y, npc[num].width, npc[num].height)))
20933 {
20934 DrawNPCCheckAlt(npc[num]);
20935 DrawNPC(num, behindTiles);
20936 }
20937 }
20938 npc[num].position -= npc[num].netOffset;
20939 }
20940 }
20941 catch
20942 {
20943 npc[num].active = false;
20944 }
20945 }
20946 }
static double Atan2(double y, double x)
static double Sqrt(double d)
static Asset< Texture2D > Chain27
static Asset< Texture2D > Chain12
static Asset< Texture2D > Chain26
static bool[] MustAlwaysDraw
Definition NPCID.cs:4248
static readonly short Count
Definition NPCID.cs:11744
void DrawNPC(int iNPCIndex, bool behindTiles)
Definition Main.cs:20956
static SpriteBatch spriteBatch
Definition Main.cs:974
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
void DrawNPCCheckAlt(NPC n)
Definition Main.cs:20948
static NPC[] npc
Definition Main.cs:1685
static int screenWidth
Definition Main.cs:1719

References System.Math.Atan2(), Terraria.GameContent.TextureAssets.Chain12, Terraria.GameContent.TextureAssets.Chain26, Terraria.GameContent.TextureAssets.Chain27, Terraria.ID.NPCID.Count, Terraria.Main.DrawNPC(), Terraria.Main.DrawNPCCheckAlt(), Terraria.Lighting.GetColor(), System.Text.RegularExpressions.i, Terraria.NPC.IsMechQueenUp, Terraria.ID.NPCID.Sets.MustAlwaysDraw, Terraria.Main.npc, Terraria.NPC.plantBoss, Terraria.Main.screenHeight, Terraria.Main.screenPosition, Terraria.Main.screenWidth, Terraria.Main.spriteBatch, System.Math.Sqrt(), System.type, and Microsoft.Xna.Framework.Graphics.Vector2.

Referenced by Terraria.Main.DoDraw_DrawNPCsBehindTiles(), Terraria.Main.DoDraw_DrawNPCsOverTiles(), and Terraria.Main.DrawCapture().