Ejemplo n.º 1
0
/*
 *	Removes the last planet from planetsList
 */
void RemoveLastPlanet()
{
	if(numberOfPlanets > 0)
	{
		deletePlanet(planetsList[numberOfPlanets-1]);
		numberOfPlanets--;
		if(numberOfPlanets != 0) //Because segfault if realloced to 0
			planetsList = realloc(planetsList, sizeof(struct PlanetStruct)*numberOfPlanets);
		PlayAudioFile(deletePlanetNoise);
	}
}
Ejemplo n.º 2
0
void deleteAllPlanets()
{
	GLuint i;
	for(i = 0; i < numberOfPlanets; i++)
		deletePlanet(planetsList[i]);
}
Ejemplo n.º 3
0
void planetThread(planet_type *planet)
{
	double atotx = 0;
	double atoty = 0;
	double r, x1, x2, y1, y2, cos, sin, G, a1, ax, ay, dt;
	planet_type *comparePlanet = database;
	G = 6.67259*pow(10, -11);
	dt = 10;
	BOOL firstLoop = TRUE;
	if (comparePlanet != 0) {
		while (1)
		{
			//	Using critical section for each whole "database-loop"
			//	as it could get messy with the pointers.
			if (firstLoop)
			{
				EnterCriticalSection(&criticalSection);
			}
			
			if (comparePlanet != planet)
			{
				x1 = planet->sx;
				y1 = planet->sy;
				x2 = comparePlanet->sx;
				y2 = comparePlanet->sy;

				r = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
				a1 = G*(comparePlanet->mass / pow(r, 2));
				cos = (x2 - x1) / r;
				sin = (y2 - y1) / r;
				ax = a1*cos;
				ay = a1*sin;
				atotx += ax;
				atoty += ay;


			}
			// If we reach the end of the loop we enter a new position for the 
			// planet and reset all the values for the next loop. 
			// Also death-check of the planet.
			if (comparePlanet->next == 0)
			{
				planet->vx += atotx*dt;
				planet->vy += atoty*dt;

				planet->sx += planet->vx*dt;
				planet->sy += planet->vy*dt;
				planet->life--;
				atotx = atoty = 0;
				
				comparePlanet = database;
				firstLoop = TRUE;
				if (planet->life <= 0)
				{
					//Remove because of life == 0
					deletePlanet(planet, "Life");
					break;
				}
				else if (planet->sx >= 800 || planet->sx <= 0)
				{
					//Remove because out of bounds in x
					deletePlanet(planet, "OOBX");
					break;
				}
				else if (planet->sy >= 600 || planet->sy <= 0)
				{
					//Remove because out of bounds in y
					deletePlanet(planet, "OOBY");
					break;
				}
				LeaveCriticalSection(&criticalSection);
				Sleep(10);
			}
			else
			{
				firstLoop = FALSE;
				comparePlanet = comparePlanet->next;
			}
			

		}
		LeaveCriticalSection(&criticalSection);
	}

	
}