Screen Armor [Updated 12/4/21]

While Doom armor provides protection, there's no real indication that anything is happening other than a HUD counter. What if the screen showed some visual indicator of a hit and how much armor was left? Perhaps, this has been addressed by other mods. This is my take.
How this works is simple. When a player is damaged if armor is in the inventory a partial screen grid of hexagons flashes on the screen. The number of hexagons drawn varies according to the amount of armor in player inventory. I've added a minimal sound effect, which of course is drowned out in close quarters. I use absolute coordinates for performance reasons, although I suppose drawing these on some kind of curve might be effective.
Can't decide how I feel about this as is - it's a work in progress - but it does the job.
- Code: Select all • Expand view
class armor_EventHandler : EventHandler
{
bool bGrid;
int tCounter;
int armor;
override void WorldLoaded(WorldEvent e)
{
bGrid = false;
}
override void RenderOverlay(RenderEvent e)
{
if (bGrid)
{
color hexColor = "Green";
int alpha = 255;
double thickness = 5;
int edge = 400;
if (armor < 100)
{
alpha = int(255 * armor / 100);
thickness = 5 * armor / 100;
}
for (int cX = 100; cX < Screen.GetWidth(); cX += 100)
{
if (cX < edge || cX > Screen.GetWidth() - edge && cX + 40 < Screen.GetWidth())
{
for (int cY = 100; cY < Screen.GetHeight() - 50; cY += 100)
{
if (Random(0, 100) < armor)
{
// top
Screen.DrawThickLine(cX - 40, cY, cX - 20, cY + 33, thickness, hexColor, alpha);
Screen.DrawThickLine(cX - 20, cY + 33, cX + 20, cY + 33, thickness, hexColor, alpha);
Screen.DrawThickLine(cX + 20, cY + 33, cX + 40, cY, thickness, hexColor, alpha);
// bottom
Screen.DrawThickLine(cX + 40, cY, cX + 20, cY - 33, thickness, hexColor, alpha);
Screen.DrawThickLine(cX + 20, cY - 33, cX - 20, cY - 33, thickness, hexColor, alpha);
Screen.DrawThickLine(cX - 20, cY - 33, cX - 40, cY, thickness, hexColor, alpha);
}
}
}
}
}
}
override void WorldTick()
{
if (tCounter < 14)
{
tCounter++;
}
else
{
bGrid = false;
}
}
override void WorldThingDamaged(WorldEvent e)
{
if (e.thing && e.thing is "PlayerPawn")
{
armor = e.thing.CountInv("BasicArmor");
if (armor > 0)
{
e.thing.A_StartSound("arhit", CHAN_BODY, CHANF_OVERLAP);
bGrid = true;
tCounter = 0;
}
}
}
}
How this works is simple. When a player is damaged if armor is in the inventory a partial screen grid of hexagons flashes on the screen. The number of hexagons drawn varies according to the amount of armor in player inventory. I've added a minimal sound effect, which of course is drowned out in close quarters. I use absolute coordinates for performance reasons, although I suppose drawing these on some kind of curve might be effective.
Can't decide how I feel about this as is - it's a work in progress - but it does the job.