//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#include "flasher.h"

int SFlasher::Handle()
{
	timer += g_fDelta;
	return 0;
}

void SFlasher::Draw()
{
	SetModelMatrix(net_transform);
	float factor = 0.5 + 0.5 * cosf(timer / period * 2 * AL_PI + phase);
	zColor cur_color = BlendColors(0x00000000, color, factor);

	DrawModeAdd();

	SetColor(cur_color);

	DrawBitmap(image, -image->w / 2, -image->h / 2, -10);

	SetColor(0xffffffff);

	DrawModeSolid();

	SetModelMatrix(g_trIdentity);
}

SFlasher* CreateFlasher(SObject* parent, float _phase, float _period, zColor _color)
{
	SFlasher* flasher = new SFlasher();
	InitObject(flasher, parent);
	flasher->phase = _phase;
	flasher->period = _period;
	flasher->color = _color;
	flasher->timer = 0;
	flasher->image = FindBitmap("flash.tga");

	return flasher;
}
