Page 1 of 1

Blink

PostPosted: Fri Nov 05, 2021 8:52 am
by Hey Doomer
Getting hurt should have real world consequences. This is my try at simulating blinking by calling FadeTo and FadeRange according to health when damaged or entering a level. Here's the ACS:

Code: Select allExpand view
#library "blink"
#include "zcommon.acs"

script "blinkEnter" ENTER
{
    int health = GetActorProperty(0, APROP_Health);

    if (health < 30)
    {
        ACS_NamedExecute("blinkVerySlow", 0, 0, 0, 0);
    }
    else if (health < 50)
    {
        ACS_NamedExecute("blinkSlow", 0, 0, 0, 0);
    }
    else
    {
        ACS_NamedExecute("blinkFast", 0, 0, 0, 0);
    }
}

script "blinkFast" (void)
{
    ACS_NamedExecuteWait("blinkOn", 0, 0, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 2, 0, 0);
    delay(35 * 2);
    ACS_NamedExecuteWait("blinkOn", 0, 0, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 1, 0, 0);
}
script "blinkSlow" (void)
{
    ACS_NamedExecuteWait("blinkOn", 0, 0, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 4, 0, 0);
    delay(35 * 4);
    ACS_NamedExecuteWait("blinkOn", 0, 1, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 2, 0, 0);
   
}
script "blinkVerySlow" (void)
{
    ACS_NamedExecuteWait("blinkOn", 0, 0, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 6, 0, 0);
    delay(35 * 6);
    ACS_NamedExecuteWait("blinkOn", 0, 2, 0, 0);
    ACS_NamedExecuteWait("blinkOff", 0, 4, 0, 0);
   
}
script "blinkOn" (int seconds)
{
    FadeTo (0, 0, 0, 1.0, seconds << 16);
}

script "blinkOff" (int seconds)
{
    FadeRange (0, 0, 0, 1.0, 0, 0, 0, 0.0, seconds << 16);
}


... and here's the event handler:

Code: Select allExpand view
class blink_EventHandler : EventHandler
{
   override
   void WorldThingDamaged(WorldEvent e)
   {
      if (e.thing && e.thing is "PlayerPawn")
      {
         if (e.thing.health < 30)
         {
            e.thing.ACS_NamedExecute("blinkVerySlow", 0, 0, 0, 0);
         }
         else if (e.thing.health < 50)
         {
            e.thing.ACS_NamedExecute("blinkSlow", 0, 0, 0, 0);
         }
         else
         {
            e.thing.ACS_NamedExecute("blinkFast", 0, 0, 0, 0);
         }
      }
   }
}


There are a few possibilities depending on how tough you think a space marine should be when shot in the face, torched by a fireball, dropped in lava, slammed by a rocket, or otherwise made to feel unloved. This works OK with "Bloody HUD:" the screen is bloody with eyes closed a moment. I've tested this minimally, and it seems to work so far as an idea.