class ZEvents : EventHandler 
{	

	bool loaded;
	TextureID barx;
	TextureID bary;
	bool showpic;
	double spread;
	int barWidth;
	
	void doStuff()
	{
		if (players[consoleplayer].ReadyWeapon == null)
		{
		} else {
			let weapPSprite = players[consoleplayer].FindPSprite(PSprite.WEAPON);
			let flashPSprite = players[consoleplayer].FindPSprite(PSprite.FLASH);
			let weapon = players[consoleplayer].ReadyWeapon;
			if (weapon && flashPSprite && weapon.inStateSequence(flashPSprite.CurState, weapon.ResolveState("Flash")))
			{
				if (spread>70) {
					spread = 70;
				} else {
					spread = spread + (70 - spread)/8;
				}
			}	
			if (spread<10) {
				spread = 10;
			} else {
				spread = spread - (spread - 10)/10;
			}
		
		}
		
		if (!loaded)
		{
			spread = 10;
			barWidth = 9;
			barx = TexMan.CheckForTexture ("zxhairx", TexMan.Type_Any);
			bary = TexMan.CheckForTexture ("zxhairy", TexMan.Type_Any);
			loaded = true;
		}
	}
	
	// PLAY scope : collect data
	override void WorldTick()
	{	
		doStuff();
		Super.WorldTick();
	}

	// UI Scope: you cannot alter data here
	override void renderOverlay(RenderEvent e) 	// UI scope
	{	
		int width = Screen.GetWidth();
		int height = Screen.GetHeight();
		double x = width * 0.5 - barWidth/2;
		double xLeft = x - spread;
		double xRight = x + spread;
		double y = 10 + height * 0.5 - barWidth/2;
		double yTop = y - spread;
		double yBot = y + spread;
		if (loaded)
			Screen.DrawTexture(barx, false, xLeft, y,
				DTA_KeepRatio, true, DTA_VirtualWidth, width, DTA_VirtualHeight, height);
			Screen.DrawTexture(barx, false, xRight, y,
				DTA_KeepRatio, true, DTA_VirtualWidth, width, DTA_VirtualHeight, height);
			Screen.DrawTexture(bary, false, x, yTop,
				DTA_KeepRatio, true, DTA_VirtualWidth, width, DTA_VirtualHeight, height);
			Screen.DrawTexture(bary, false, x, yBot,
				DTA_KeepRatio, true, DTA_VirtualWidth, width, DTA_VirtualHeight, height);
	}
}