// Speakers.vtx
// Author - MrC

float[] x(15), y(15), vx(15), vy(15);

Texture speaker;

void Init()
{
   speaker.LoadTexture("speaker.png");
   
   for (int i = 0; i < 15; i++)
   {
		x[i] = (Rand()-0.5) * 2;
		y[i] = (Rand()-0.5) * 2;
		vx[i] = (Rand()-0.5) * 0.05;
		vy[i] = (Rand()-0.5) * 0.05;
   }
}

void quad(float x, float y, float sz)
{
   gfxTexCoord(0,0);
   gfxVertex(x-sz,y+sz,0);
   gfxTexCoord(1,0);
   gfxVertex(x+sz,y+sz,0);
   gfxTexCoord(1,1);
   gfxVertex(x+sz,y-sz,0);
   gfxTexCoord(0,1);
   gfxVertex(x-sz,y-sz,0);
}

float time = 0;

void Render()
{
	time += TIMEPASS * 30;

	for (int i = 0; i < 15; i++)
	{
		float value;
		if (i < 5)
			value = BASS;
		else if (i < 10)
			value = MIDDLE;
		else
			value = TREBLE;

						
		x[i] = x[i] + vx[i] * value;
		if (x[i] < -1)
		{
			x[i] = -1;
			vx[i] = -vx[i];
		}
		else if (x[i] > 1)
		{
			x[i] = 1;
			vx[i] = -vx[i];
		}
		y[i] = y[i] + vy[i] * value;
		if (y[i] < -1)
		{
			y[i] = -1;
			vy[i] = -vy[i];
		}
		else if (y[i] > 1)
		{
			y[i] = 1;
			vy[i] = -vy[i];
		}
	}


	gfxSetTexture(speaker);
	gfxSetAspect(1);
	gfxTranslate(0, 0, 2.0);
	gfxBegin(PRIM_QUADLIST);
	gfxColour(1.0f, 1.0f, 1.0f, 1);
	gfxSetBlendMode(BLEND_MOD);
	for (int i=0; i < 5; i++)
	{
		quad(x[i], y[i], 0.1 + (1+BASS)*0.2);
	}
	for (int i=5; i < 10; i++)
	{
		quad(x[i], y[i], 0.1 + (1+MIDDLE)*0.2);
	}
	for (int i=10; i < 15; i++)
	{
		quad(x[i], y[i], 0.1 + (1+TREBLE)*0.2);
	}
	gfxEnd();
	
}