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

◆ DrawHealthBar()

void Terraria.Main.DrawHealthBar ( float X,
float Y,
int Health,
int MaxHealth,
float alpha,
float scale = 1f,
bool noFlip = false )
inline

Draws a small health bar.
F:Terraria.Main.spriteBatch should already be started before calling this method.

Parameters
XThe x-coordinate of the health bar in world coordinates.
YThe y-coordinate of the health bar in world coordinates.
HealthThe current health displayed. The health bar is drawn Health / MaxHealth percent full.
If Health <= 0, no health bar is drawn.
If Health > MaxHealth , the health bar will not exceed max capacity.
MaxHealthThe maximum health displayed. The health bar is drawn Health / MaxHealth percent full.
alphaThe opacity of the healthbar, where 0f is transparent and 1f is opaque.
scaleThe visual scale of the health bar.
noFlipIf true, then the health bar will not adjust its y-position for players with reversed gravity.

Definition at line 21442 of file Main.cs.

21443 {
21444 //IL_03d9: Unknown result type (might be due to invalid IL or missing references)
21445 //IL_03eb: Unknown result type (might be due to invalid IL or missing references)
21446 //IL_03f5: Unknown result type (might be due to invalid IL or missing references)
21447 //IL_0406: Unknown result type (might be due to invalid IL or missing references)
21448 //IL_0370: Unknown result type (might be due to invalid IL or missing references)
21449 //IL_0385: Unknown result type (might be due to invalid IL or missing references)
21450 //IL_038f: Unknown result type (might be due to invalid IL or missing references)
21451 //IL_03a0: Unknown result type (might be due to invalid IL or missing references)
21452 //IL_01a9: Unknown result type (might be due to invalid IL or missing references)
21453 //IL_01bb: Unknown result type (might be due to invalid IL or missing references)
21454 //IL_01c5: Unknown result type (might be due to invalid IL or missing references)
21455 //IL_01d6: Unknown result type (might be due to invalid IL or missing references)
21456 //IL_021c: Unknown result type (might be due to invalid IL or missing references)
21457 //IL_0235: Unknown result type (might be due to invalid IL or missing references)
21458 //IL_023f: Unknown result type (might be due to invalid IL or missing references)
21459 //IL_0250: Unknown result type (might be due to invalid IL or missing references)
21460 //IL_02fd: Unknown result type (might be due to invalid IL or missing references)
21461 //IL_0310: Unknown result type (might be due to invalid IL or missing references)
21462 //IL_031a: Unknown result type (might be due to invalid IL or missing references)
21463 //IL_032b: Unknown result type (might be due to invalid IL or missing references)
21464 //IL_028d: Unknown result type (might be due to invalid IL or missing references)
21465 //IL_02a1: Unknown result type (might be due to invalid IL or missing references)
21466 //IL_02ab: Unknown result type (might be due to invalid IL or missing references)
21467 //IL_02bc: Unknown result type (might be due to invalid IL or missing references)
21468 if (Health <= 0)
21469 {
21470 return;
21471 }
21472 float num = (float)Health / (float)MaxHealth;
21473 if (num > 1f)
21474 {
21475 num = 1f;
21476 }
21477 int num2 = (int)(36f * num);
21478 float num3 = X - 18f * scale;
21479 float num4 = Y;
21480 if (player[myPlayer].gravDir == -1f && !noFlip)
21481 {
21482 num4 -= screenPosition.Y;
21483 num4 = screenPosition.Y + (float)screenHeight - num4;
21484 }
21485 float num5 = 0f;
21486 float num6 = 0f;
21487 float num7 = 0f;
21488 float num8 = 255f;
21489 num -= 0.1f;
21490 if ((double)num > 0.5)
21491 {
21492 num6 = 255f;
21493 num5 = 255f * (1f - num) * 2f;
21494 }
21495 else
21496 {
21497 num6 = 255f * num * 2f;
21498 num5 = 255f;
21499 }
21500 float num9 = 0.95f;
21501 num5 = num5 * alpha * num9;
21502 num6 = num6 * alpha * num9;
21503 num8 = num8 * alpha * num9;
21504 if (num5 < 0f)
21505 {
21506 num5 = 0f;
21507 }
21508 if (num5 > 255f)
21509 {
21510 num5 = 255f;
21511 }
21512 if (num6 < 0f)
21513 {
21514 num6 = 0f;
21515 }
21516 if (num6 > 255f)
21517 {
21518 num6 = 255f;
21519 }
21520 if (num8 < 0f)
21521 {
21522 num8 = 0f;
21523 }
21524 if (num8 > 255f)
21525 {
21526 num8 = 255f;
21527 }
21528 Color color = default(Color);
21529 ((Color)(ref color))._002Ector((int)(byte)num5, (int)(byte)num6, (int)(byte)num7, (int)(byte)num8);
21530 if (num2 < 3)
21531 {
21532 num2 = 3;
21533 }
21534 if (num2 < 34)
21535 {
21536 if (num2 < 36)
21537 {
21538 spriteBatch.Draw(TextureAssets.Hb2.Value, new Vector2(num3 - screenPosition.X + (float)num2 * scale, num4 - screenPosition.Y), (Rectangle?)new Rectangle(2, 0, 2, TextureAssets.Hb2.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21539 }
21540 if (num2 < 34)
21541 {
21542 spriteBatch.Draw(TextureAssets.Hb2.Value, new Vector2(num3 - screenPosition.X + (float)(num2 + 2) * scale, num4 - screenPosition.Y), (Rectangle?)new Rectangle(num2 + 2, 0, 36 - num2 - 2, TextureAssets.Hb2.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21543 }
21544 if (num2 > 2)
21545 {
21546 spriteBatch.Draw(TextureAssets.Hb1.Value, new Vector2(num3 - screenPosition.X, num4 - screenPosition.Y), (Rectangle?)new Rectangle(0, 0, num2 - 2, TextureAssets.Hb1.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21547 }
21548 spriteBatch.Draw(TextureAssets.Hb1.Value, new Vector2(num3 - screenPosition.X + (float)(num2 - 2) * scale, num4 - screenPosition.Y), (Rectangle?)new Rectangle(32, 0, 2, TextureAssets.Hb1.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21549 }
21550 else
21551 {
21552 if (num2 < 36)
21553 {
21554 spriteBatch.Draw(TextureAssets.Hb2.Value, new Vector2(num3 - screenPosition.X + (float)num2 * scale, num4 - screenPosition.Y), (Rectangle?)new Rectangle(num2, 0, 36 - num2, TextureAssets.Hb2.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21555 }
21556 spriteBatch.Draw(TextureAssets.Hb1.Value, new Vector2(num3 - screenPosition.X, num4 - screenPosition.Y), (Rectangle?)new Rectangle(0, 0, num2, TextureAssets.Hb1.Height()), color, 0f, new Vector2(0f, 0f), scale, (SpriteEffects)0, 0f);
21557 }
21558 }
static Asset< Texture2D > Hb2
static Asset< Texture2D > Hb1
static SpriteBatch spriteBatch
Definition Main.cs:1043
static int myPlayer
The index in F:Terraria.Main.player of this client's Player. If this is 255, this client is the ser...
Definition Main.cs:1958
static int screenHeight
Definition Main.cs:1870
static Vector2 screenPosition
The position of the top left corner of the screen in world coordinates. Modify in M:Terraria....
Definition Main.cs:1864
static Player[] player
Definition Main.cs:1960

References Terraria.Graphics.Light.Color, Terraria.GameContent.TextureAssets.Hb1, Terraria.GameContent.TextureAssets.Hb2, Terraria.Main.myPlayer, Terraria.Main.player, Terraria.Main.screenHeight, Terraria.Main.screenPosition, and Terraria.Main.spriteBatch.

Referenced by Terraria.Main.DrawInterface_14_EntityHealthBars(), and Terraria.Main.DrawInterface_Healthbar_Worm().

+ Here is the caller graph for this function: