// GraphicsTemplate.cpp
// 
//////////////////////////////////////////////////////////////////////////////////////////
// includes 
//////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

//////////////////////////////////////////////////////////////////////////////////////////
// externals 
//////////////////////////////////////////////////////////////////////////////////////////
extern cRenderClass graphics;


//////////////////////////////////////////////////////////////////////////////////////////
// renderScene() - render the scene
//////////////////////////////////////////////////////////////////////////////////////////
bool keyy = 0;      //Add particle flag or not, not initially

void renderScene1()
{
	// Configure a point (color RGB value 1:0.5:1, size 10, coordinates 250:250)
	//graphics.setColor(1.0f, 0.5f, 0.1f);
	graphics.setPointSize(5);//size of particle
	if (keyy)
	{
		for (int i = 0; i < 50; i++) //Add 50 particles each time


		{
			graphics.new_cParticle();
		}
	}

	int delet_buff[cParticle_Max];    //Note where to delete
	int delet_num = 0;                  //Write down the number to delete

	for (int i = 0; i < graphics.get_num(); i++)
	{
		cParticle* pixel = graphics.get_cParticle(i);          //Get the class pointer of the ith point
		int x = (int)pixel->Position_x;
		int y = (int)pixel->Position_y;
		if (x<0 || y<0 || x>graphics.m_sw || y>graphics.m_sh)  //Jump out range
		{
			pixel->ActiveFlag = 0;
		}
		if (pixel->ActiveFlag == 0)
		{
			delet_buff[delet_num] = i;
			delet_num++;
			continue;
		}
		graphics.setColour(pixel->r, pixel->g, pixel->b);    //Set color
		graphics.drawPixel(x, y);                             //Set position
		// render the scene
	}
	for (int i = 0; i < delet_num; i++)    //delete invalid particles
	{
		graphics.delet_cParticle(delet_buff[delet_num - i - 1]);
	}
	for (int i = 0; i < graphics.get_num(); i++)
	{
		cParticle* pixel = graphics.get_cParticle(i);          //Get the class pointer of the ith point
		pixel->run();
	}
	graphics.render();    //display
	Sleep(time_life);           //Delay 200ms
}
void renderScene2()
{
	for (int i = 0; i < 10; i++)
	{
		// Configure a point (color RGB value 1:0.5:1, size 10, coordinates 250:250)
		graphics.setColour(1.0f, 0.5f, 0.1f);
		graphics.setPointSize(i);
		graphics.drawPixel(200.0f, 200.0f);
		// render the scene
		graphics.render();
	}

}

//////////////////////////////////////////////////////////////////////////////////////////
// update() - update function
//////////////////////////////////////////////////////////////////////////////////////////
void update()
{
	/////////////////////////////////////////////
	// update your particle here..
	/////////////////////////////////////////////



	// always re-render the scene..
	renderScene1();
	//renderScene2();
}



//////////////////////////////////////////////////////////////////////////////////////////
// _tmain() - program entry point
//////////////////////////////////////////////////////////////////////////////////////////
int _tmain(int argc, _TCHAR* argv[])
{
	// init glut stuff..
	graphics.create(argc, argv);

	// good place for one-off initialisations and objects creation..

	// enter game loop..
	graphics.loop();

	return 0;
}




