#include "stdafx.h"
Utils utils;

char buffer;

cParticle::cParticle() {
	this->isAlive = true;
	this->Pos_x = 600.0f;
	this->Pos_y = 600.0f;
	this->Acc_x = 0.0001;
	this->Acc_y = 0.001;
	this->endtime = 0;
}

cParticle::~cParticle() {

}

void cParticle::update() {
	this->Acc_x -= 0.00003;
	if (this->Vel_x > 0.0f) {
		this->Vel_x += Acc_x;
	}else {
		this->Vel_x -= Acc_x;
	}
	this->Pos_x += Vel_x;

	this->Acc_y += 0.0004;
	this->Vel_y -= Acc_y;
	this->Pos_y += Vel_y;
}

void cParticle::setVel() {
	this->Vel_x = utils.unirand(-1.0, 1.0);
	this->Vel_y = utils.unirand(-1.0, 1.0);
}

void cParticle::setRandomPosition() {
	this->Pos_x = utils.unirand(0, 1200);	
	this->Pos_x = utils.unirand(400, 800);
}

void cParticle::setColor() {
	srand(int(time(NULL)));
	this->RGBAs[0] = float(rand() % 255) / 255;
	this->RGBAs[1] = float(rand() % 255) / 255;
	this->RGBAs[2] = float(rand() % 255) / 255;
}

//Press Enter to stop rendering when isAlive equals true
void cParticle::checkStop() {
	if ((GetAsyncKeyState(VK_RETURN) & 0x0D) && this->isAlive == true) {
		this->isAlive = false;
		cout << "Stop !" << endl;	
		cout << "Press [s] to restart !" << endl;
		cout << endl;
		Sleep(10);
	}
}

void cParticle::checkStart() {
	char ch = _getch();
	if (ch == 's' || ch == 'S') {
		this->isAlive = true;
		this->starttime = GetTickCount();
		this->endtime = GetTickCount();
		cout << "Start !" << endl;
		cout << "Press Enter to stop !" << endl;
		cout << endl;
		Sleep(10);
	}
}