예제 #1
0
int main(int argc, char** argv)
{
	// Starting game window size.

	height = 960;
	width = 1000;

	//Initialize Object Data

	srand(time(NULL));

	// Initialize Tank
	float randomAngle = (float)random(0, 200) / 10;

	artillery = tank(random(-width * 24, width * 24), random(-height * 24, height * 24), 1500, 15, randomAngle);

	player = Rocket(0,0, 100, 0.8f, 10);
	player.follow(artillery); //Sets initial Position to tank

	UI = new UIManager();

	moonLand = random(0, numMoons-1);
	seed = random(-123456, 123456); // Level seed to randomize each level creation between min and max value. 
	int sizeOfMoonLoc = -1; 
	artillery.colRadius = artillery.radius * distanceFromStartMult;
	for (int i = 0; i < numMoons; i++)
	{
		sizeOfMoonLoc++;
		moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24));
		float moonRadius = random(300, 500);
		moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, 60);

		for (int z = 0; z < sizeOfMoonLoc; z++)
		{
			if (z != i)
			{
				while (moons[i].checkCollision(moons[z]) || moons[i].checkCollision(artillery))
				{
					moonLocation[i] = vector(random(-width * 24, width * 24), random(-height * 24, height * 24));
					moons[i] = Moon(moonLocation[i], moonRadius, 0, 0, 0, round(moonRadius / 10));
				}
				
			}
		}
	}
	artillery.colRadius = artillery.radius;
	for (int i = 0; i < numStars; i++)
	{
		star[i] = new Star(vector(random(-width*24,width*24), random(-height*24,height*24)), vector(0.8f, 0.8f, 0.0f), random(3, 15), random(0,100));
	}

	//End of Initialization

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(0,0);
	glutInitWindowSize(width, height);
	glutCreateWindow("IchyMoo the LunarLunar");
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(0.05, 0.05, 0.05, 0.0);
	glutReshapeFunc(reshape);
	glutDisplayFunc(renderScene);
	glutKeyboardFunc(keyDown);
	glutKeyboardUpFunc(keyUp);
	glutTimerFunc(41,idle,0);
	glutMainLoop();
}
예제 #2
0
void idle(int value)
{

	glutTimerFunc(41, idle, 0);

	// Lunar-lander Shooting from cannon.

	if (artillery.getLock())
	{
		if (!artillery.checkRocketRelease())
		{
			float playerAngle = artillery.getPlayerAngle();
			float cannonAngle = artillery.getCannonRotate();
			float AdjPlayerAngle = playerAngle;

			int turns = ceil(abs(playerAngle) / (2 * M_PI)) - 1;

			if (turns >= 1)
			{
				if (playerAngle< 0)
				{
					AdjPlayerAngle = playerAngle + (M_PI *  2) * turns;
				}
				else
				{
					AdjPlayerAngle = playerAngle - (M_PI * 2) * turns;
				}
			}
			player.setVelocity(40, (M_PI/2) - AdjPlayerAngle + cannonAngle);
		}
		artillery.setRocketRelease(true);
	}

	//Calculate Physics for each frame

	for (int i = 0; i < numStars; i++)
	{
		star[i]->update();
	}
	for (int i = 0; i < numMoons; i++)
	{
		player.gravitateTo(moons[i]);
		if (i == moonLand)
		{
			player.update(moons[i], true);
		}
		else
		{
			player.update(moons[i], false);
		}
	}
	player.update(artillery, false);
	player.gravitateTo(artillery);
	player.update();
	artillery.updateTank();
	if (!artillery.getLock())
	{
		player.follow(artillery);
	}
	

	/* End of Calculation */
	glutPostRedisplay();
}