#include <hge.h>
#include <hgesprite.h>
#include <hgeparticle.h>
#include <math.h>
#include <mmsystem.h>
#include "Blood.h" 
#include "Global.h"

TBlood::TBlood()
{
	ZeroMemory(Point, sizeof(Point));
	MaxBlood = 0;
	texType1 = hge->Texture_Load("Blood_1.png");
	sprType1 = new hgeSprite(texType1, 0, 0, 32, 32);
	sprType1->SetHotSpot(16, 16);

}

TBlood::Add(float x, float y, int BloodType, float time)
{
	int Index = -1;

	for(int i=0; i<10000; i++)//ищем пустое место
	{
		if(Point[i].type==0)
		{
			Index = i;
			break;
		}
	}

	if(Index != -1)//Если нашли место - помещаем туда
	{
		Point[Index].rotation = hge->Random_Float(0, 6.38f);
		Point[Index].time = time;
		Point[Index].type = BloodType;
		Point[Index].x = x;
		Point[Index].y = y;

		if(Index == MaxBlood) MaxBlood++; 
	}
}

TBlood::Delete(int Index)
{
	Point[Index].rotation = 0;
	Point[Index].time = 0;
	Point[Index].type = 0;
	Point[Index].x = 0;
	Point[Index].y = 0;
	//while(Point[Index-1].type==0)
	//		MaxBlood--;
}

TBlood::Update(float dt)
{
	for(int i=0; i<MaxBlood; i++)
	{
		if(Point[i].type!=0)
		{
			Point[i].time -= dt;
			if(Point[i].time < 0)
				Delete(i);
		}
	}
}

TBlood::Render(float X, float Y)
{
	for(int i=0; i<MaxBlood; i++)
	{
		if(Point[i].type!=0)
		{
			sprType1->RenderEx(Point[i].x-X, Point[i].y-Y, Point[i].rotation, 1.0, 0);
		}
	}
}