#include "cParticle.h"
#include <stdio.h>
#include <Windows.h>
#include <math.h>

#define pi 3.1415926
#define jindu 30           //How many directions does a circle divide into
cParticle::cParticle()
{
	Life = (int)(rand() / double(RAND_MAX) * (1000 - 100) + 100);      //Randomly generate 100-1000 units: scale
	Velocity = (float)(rand() / double(RAND_MAX) * 0.1);                //Random generation speed 0 ~ 0.25 unit: pixel / MS
	//Direction = (float)(rand() / double(RAND_MAX)*2*pi);              //Random generation direction
	Direction = (float)(rand() % jindu) * 2 * pi / jindu;              //Random generation direction
	r = (float)(rand() / double(RAND_MAX));
	g = (float)(rand() / double(RAND_MAX));
	b = (float)(rand() / double(RAND_MAX));

	//The initial position is the center position of the interface
	Position_x = 250.0f;
	Position_y = 250.0f;

	ActiveFlag = true;    //ActiveFlag to decide whether the particle is alive
}


cParticle::~cParticle()
{
}

void cParticle::run()
{
	Position_x += time_life * cos(Direction) * Velocity;  //X after move
	Position_y += time_life * sin(Direction) * Velocity;  //Y after move
	Life--;
	if (Life == 0)
	{
		ActiveFlag = false;
	}
}
