#include "stdafx.h"

utils uti;

cParticles::cParticles() {
		pos_x = 250.0f;
		pos_y = 250.0f;
		vel_x = 2.0f;
		vel_y = 2.0f;
		res_x = 0.01f;//0.01
		res_y = -0.1f;//0.1
		active = true;
		//startTime = GetTickCount();

}

cParticles::~cParticles() {
	
}

void cParticles::update() {
	 
	if (pos_y < boomPoint&&isBoom == false)
	{
		pos_y = pos_y + upSpeed;
	}
	else
	{
		isBoom = true;
		pos_x = pos_x + vel_x;
		pos_y = pos_y + vel_y;

		//if (vel_x >= 0) {
		//	vel_x = vel_x + res_x;
		//	if (vel_y >= 0) {
		//		vel_y = vel_y + res_y;
		//	}
		//}
		//else {
		//	vel_x = vel_x - res_x;
		//	if (vel_y < 0) {
		//		vel_y < vel_y - res_y;
		//	}
		//}
		vel_x = vel_x + res_x;
		vel_y = vel_y + res_y;

		life--;
		//endTime = GetTickCount();

		judge();
	}	
}
//bool cParticles::judge() {
//	//pos_x<0 || pos_x>SCREEN_WIDTH || pos_y<0 || pos_x>SCREEN_HEIGHT ||
//	if (endTime >= startTime + life * 1000) {
//		turnOff();
//	}
//	if (pos_x<0 || pos_x>SCREEN_WIDTH || pos_y<0 || pos_x>SCREEN_HEIGHT) {
//		turnOff();
//	}
//	return active;
//	
//}
void cParticles::judge() {
	
		if (life<=0||pos_x<0 || pos_x>SCREEN_WIDTH || pos_y<0 || pos_x>SCREEN_HEIGHT) {
			/*turnOff();*/
			this->active = false;
		}
}

void  cParticles::init(float x, float y ,float m, float n) {
		active = true;
		life = 100;
		//startTime = GetTickCount();
		this->pos_x = x;//SCREEN_WIDTH / 2;
		this->pos_y = y;//500.0f;
		this->vel_x = uti.unirand(-1.0f, 2.0f);
		this->vel_y = uti.unirand(4.0f, 6.0f);
		this->boomPoint = m;
		this->upSpeed = n;
	}

//void  cParticles::turnOff() {
//		this->active = false;
//	}
