#library "30Health"
#include "zcommon.acs"

#define MAX_VOLUME 127

script "30Health" ENTER
{
	int width = 640, height = 480;
	SetHudSize(width, height, 0);
	SetFont("M_INJ");

	// Half width and height (in fixed-point).
	int half_width  = (width / 2) << 16;
	int half_height = (height / 2) << 16;


	while (true)
	{
		int health = GetActorProperty(0, APROP_HEALTH);
		if (health > 0 && health <= 30)
		{
			HudMessage(s:"A"; HUDMSG_FADEINOUT, 0, CR_WHITE, half_width, half_height, 0.0, 0.5, 0.5);

			// Volume and delay of heartbeat (faster and louder with less health).
			int volume = MAX_VOLUME;
			int delay1 = 10;
			int delay2 = 14;

			if (health > 20)
			{
				volume = MAX_VOLUME - 50;
				delay1 = 21;
				delay2 = 34;
			}
			else if (health > 10)
			{
				volume = MAX_VOLUME - 25;
				delay1 = 18;
				delay2 = 24;
			}

			LocalAmbientSound("hbeat", volume);
			Delay(delay1);
			LocalAmbientSound("hbeat", volume);
			Delay(delay2);
		}

		Delay(1);
	}
}