Пример #1
0
bool GameController::Setup()
{
	DisplayInstructions();
	world->Start();
	player->Start();
	monster->Start();

	return true;
} // End of Setup function
Пример #2
0
bool GameController::ProcessFrame(const float deltaTime)
{
	if (GetAsyncKeyState('I') & 0x0001)
		DisplayInstructions();

	// If monster is still alive then go on with the game.
	if (monster->GetAlive() && player->GetAlive())
	{
		world->ProcessTurn(deltaTime, player->GetAudioListener());

		// Player Turn.
		player->ProcessTurn(deltaTime, monster->GetPosition());

		// Monster Turn.
		monster->ProcessTurn(deltaTime, player->GetPosition(), player->GetAudioListener());
	}
	else
	{
		// Game has finished, go into fail state.
	}

	return true;
} // End of ProcessFrame function
Пример #3
0
//overall display function
void DisplayFunc()
{
	window.FPS++;
	float current_time = (glutGet(GLUT_ELAPSED_TIME)) / 1000.0f;
	current_time = current_time - window.total_time_paused;
	ostringstream convert;
	convert << (int)current_time;
	string display_current_time = convert.str();

	glEnable(GL_LINE_SMOOTH);
	glEnable(GL_POLYGON_SMOOTH);

	if (!window.paused)
	{
		glDisable(GL_CULL_FACE);

		glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, window.size.x, window.size.y);

		mat4 projection;

		if (debug_mode != 3)
			projection = perspective(20.0f, window.aspect, 1.0f, 600.0f);
		else 
			projection = perspective(30.0f, window.aspect, 1.0f, 600.0f);

		radius = 20.1f;

		float tempX = xpos;
		float tempZ = zpos;
		float tempLookatX = lookatX;
		float tempLookatZ = lookatZ;

		mat4 modelview;

		//movement (with a buffer zone in center) in first person view
		if ((debug_mode != 2 && debug_mode != 0) && (xDiffFromCenter > 0.5f || xDiffFromCenter < -0.5f || yDiffFromCenter > 0.5f || yDiffFromCenter < -0.5f))
		{

			if ((xpos <= -105.0f + window.ball_radius || xpos >= 105 - window.ball_radius))	//bounce off walls
			{
				lookatX = xpos - (lookatX - xpos);
				angleV = -angleV;
				window.hit_something = true;
			}
			if ((zpos <= -105.0f + window.ball_radius  || zpos >= 105.0f - window.ball_radius))	//bounce off walls
			{
				lookatZ = zpos - (lookatZ - zpos);
				while (angleV < 0.0f)
					angleV = 360.0f + angleV;
				angleV = 180 - angleV;
				window.hit_something = true;
			}


			// turn right or left
			angleV = angleV - xDiffFromCenter * 0.1f;
			lookatX = xpos - sin(angleV * (PI / 180)) * radius ;
			lookatZ = zpos - cos(angleV * (PI / 180)) * radius;

			//move forward and backwards
			xpos = xpos + ((lookatX - xpos) * yDiffFromCenter * 0.02f );	//multiply by level to compensate adding more balls and
			//slowing down of processing them
			zpos = zpos + ((lookatZ - zpos) * yDiffFromCenter * 0.02f);
			ypos = ypos + ((0 - ypos) * 0.003f);

			zpos = clamp(zpos, -104.5f, 104.5f);
			xpos = clamp(xpos, -104.5f, 104.5f);

		}

		//movement in third person view
		if ((debug_mode == 2 || debug_mode == 0) && (xDiffFromCenter > 0.5f || xDiffFromCenter < -0.5f))
		{
			angleH = angleH - xDiffFromCenter * 0.05f;
			cameraX = sin(angleH * (PI / 180)) * 110.0f;
			cameraZ = cos(angleH * (PI / 180)) * 110.0f;
		}

		if (debug_mode == 0 && (yDiffFromCenter > 0.5f || yDiffFromCenter < -0.5f))
		{
			angleh = angleh + yDiffFromCenter * 0.05f;
			cameraY = sin(angleh * (PI / 180)) * 110.0f;
		}

		//check to see if going to hit a box and calculate position
		for (int i = 0; i < (int)boxes.size(); i++)
		{
			if (xpos >= (boxes.at(i).getPostion().x - window.obstacle_width/2.0f - window.ball_radius) 
				&&  xpos <= (boxes.at(i).getPostion().x + window.obstacle_width/2.0f + window.ball_radius))
			{
				if (zpos >= (boxes.at(i).getPostion().z - window.obstacle_width/2.0f - window.ball_radius)
					&& (zpos) <= (boxes.at(i).getPostion().z + window.obstacle_width/2.0f + window.ball_radius))
				{	

					boxes.at(i).setForce(yDiffFromCenter);
					float direction_X; 
					direction_X = boxes.at(i).getPostion().x - xpos;
					float direction_Z; 
					direction_X = boxes.at(i).getPostion().z - zpos;
					boxes.at(i).setDirection(vec3(direction_X, ypos, direction_Z));

					window.hit_something = true;

					/*cout << boxes.at(i).getPostion().x << ", " << boxes.at(i).getPostion().z << ", " << i << endl;
					cout << "Force: " << boxes.at(i).getForce() << endl;
					cout << "direction: " << boxes.at(i).getDirection().x << ", " << boxes.at(i).getDirection().z << endl;*/

					if (zpos < boxes.at(i).getPostion().z - window.obstacle_width/2.0f || zpos > boxes.at(i).getPostion().z + window.obstacle_width/2.0f)
					{
						//lookatX = tempLookX;
						lookatZ = zpos - (lookatZ - zpos);

						while (angleV < 0.0f)
							angleV = 360.0f + angleV;

						angleV = 180 - angleV;
						//cout << "hit z side " << endl;
					}

					else if (xpos < boxes.at(i).getPostion().x - window.obstacle_width/2.0f || xpos > boxes.at(i).getPostion().x + window.obstacle_width/2.0f)
					{
						lookatX = xpos - (lookatX - xpos);
						angleV = -angleV;

						//cout << "hit x side " << endl;
					}

				}
			}
			//boxes.at(i) = Object_movement(boxes.at(i), boxes.at(i).getPostion(), boxes.at(i).getForce(), boxes.at(i).getDirection()); 
		}

		//check to see if hitting ball
		for(int i = 0; i < window.num_balls; i++)
		{
			if (xpos  >= (balls.at(i).getPostion().x - window.ball_radius - window.ball_radius) 
				&& (xpos)  <= (balls.at(i).getPostion().x + window.ball_radius + window.ball_radius))
			{
				if (zpos >= (balls.at(i).getPostion().z - window.ball_radius - window.ball_radius) 
					&& (zpos)  <= (balls.at(i).getPostion().z + window.ball_radius + window.ball_radius))
				{	
					if (i == 10)
					{
						window.gameOver = true;
						xpos = tempX;
						zpos = tempZ;
						debug_mode = 2;
					}

					balls.at(i).hit(current_time + 30.0f + (float)window.num_balls * 2.0f, current_time); // set the timer for the ball

					glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

					lookatZ = zpos - (lookatZ - zpos);
					lookatX = xpos - (lookatX - xpos);

					//use pythagorean theorem and law of cosines to find angle
					float distanceA = sqrt(pow((balls.at(i).getPostion().x - xpos), 2) + pow((balls.at(i).getPostion().z - zpos), 2));
					float distanceB = sqrt(pow((lookatX - balls.at(i).getPostion().x), 2) + pow((lookatZ - balls.at(i).getPostion().z), 2));
					float distanceC = sqrt(pow((xpos - lookatX), 2) + pow((zpos - lookatZ), 2));

					float angleTemp = acos((pow(distanceB, 2) - pow(distanceA, 2) - pow(distanceC, 2)) / (2 * distanceA * distanceC));

					//cout << "original: " << angleV << endl;
					//cout << "angleTemp: " << angleTemp << endl;
					if (yDiffFromCenter >= 0.0f)
						angleV = angleV + 90 - angleTemp * 5.0f;
					else
						angleV = angleV - 90 - angleTemp * 5.0f;
					//cout << "new angle: " << angleV << endl;

					window.hit_something = true;
				}
			}
		}


		if (debug_mode == 1)
		{
			modelview = lookAt(vec3(xpos, ypos, zpos), vec3(lookatX, ypos, lookatZ), vec3(0.0f, 1.0f, 0.0f));
		}
		else if (debug_mode == 2)
		{
			modelview = lookAt(vec3(cameraX, 30.0f, cameraZ), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
		}
		else if (debug_mode == 3)
		{
			modelview = lookAt(vec3(0.1f, 400.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f));
		}
		else
		{
			modelview = lookAt(vec3(0.0f, 0.0f, 0.0f), vec3(cameraX, cameraY, cameraZ), vec3(0.0f, 1.0f, 0.0f));
		}

		//FrameBuffering
		RenderIntoFrameBuffer(modelview, projection);
		glViewport(0, 0, window.size.x, window.size.y);

		RenderIntoFrameBuffer2(modelview, projection);
		glViewport(0, 0, window.size.x, window.size.y);

		DisplayFuncClock();
		glViewport(0, 0, window.size.x, window.size.y);

		glPolygonMode(GL_FRONT_AND_BACK, window.wireframe ? GL_LINE : GL_FILL);

		//Draw skybox
		if (debug_mode != 3)
			sky.Draw(projection, modelview, window.size, window.stage, window.shader);

		if (debug_mode != 0)
		{

			//Draw map elements (ground and walls)
			modelview = translate(modelview, vec3(0.0f, -1.0f, 0.0f));
			trueGround.Draw_floors(projection, modelview, window.size, fbo2, current_time);
			walls.Draw_walls(projection, modelview, window.size);
			modelview = translate(modelview, vec3(0.0f, 1.0f, 0.0f));

			//Draw jumbotrons and scoreboards
			modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f));
			tron.Draw(projection, modelview, window.size, window.stage, window.shader);
			screen.DrawScreen(projection, modelview, window.size, fbo, 0);
			modelview = translate(modelview, vec3(0.0f, 4.5f, -0.2f));
			screen.DrawScreen(projection, modelview, window.size, fbo, 5); //Draw one jumbotron with the field name
			modelview = translate(modelview, vec3(0.0f, -4.5f, 0.2f));
			modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f));
			modelview = rotate(modelview, 180.0f, vec3(0.0f, 1.0f, 0.0f));
			modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f));
			tron.Draw(projection, modelview, window.size, window.stage, window.shader);
			screen.DrawScreen(projection, modelview, window.size, fbo, 0);
			modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f));
			modelview = rotate(modelview, 90.0f, vec3(0.0f, 1.0f, 0.0f));
			modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f));
			/*score.Draw(projection, modelview, window.size, window.stage, window.shader);
			scoreScreen.DrawScreen(projection, modelview, window.size, window.stage, fbo2); */
			tron.Draw(projection, modelview, window.size, window.stage, window.shader);
			screen.DrawScreen(projection, modelview, window.size, fbo, 0);
			modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f));
			modelview = rotate(modelview, 180.0f, vec3(0.0f, 1.0f, 0.0f));
			modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f));
			//score.Draw(projection, modelview, window.size, window.stage, window.shader);
			tron.Draw(projection, modelview, window.size, window.stage, window.shader);
			screen.DrawScreen(projection, modelview, window.size, fbo, 0);
			modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f));
			modelview = rotate(modelview, -90.0f, vec3(0.0f, 1.0f, 0.0f));

			//Draw player (and other objects)
			modelview = translate(modelview, vec3(0.0f, -1.0f, 0.0f));
			modelview = translate(modelview, vec3(0.0f, window.ball_radius, 0.0f));	//make sure balls are on ground
			modelview = translate(modelview, vec3(xpos, ypos, zpos));
			
			if (debug_mode != 1)
				player.Draw(projection, modelview, window.size, window.stage, window.shader);
			modelview = translate(modelview, vec3(-xpos, -ypos, -zpos));

			window.num_hit = 0;
			for (int i = 0; i < window.num_balls; i++)	//places the desired number of balls on field
			{
				modelview = translate(modelview, balls.at(i).getPostion());	//places in random location
				if (i == 10)
				{
					bomb.Draw(projection, modelview, window.size, window.stage, window.shader, current_time); //Place a bomb (not in lower levels)
				}
				else if (balls.at(i).is_sphere_hit())
				{
					ball2.Draw(projection, modelview, window.size, window.stage, window.shader, current_time);
					balls.at(i).setTime(current_time); //set time and display remaining time above ball
					DisplayTime(modelview, projection,  balls.at(i).getEndTime() - balls.at(i).getTime(), balls.at(i).getPostion()); 
					window.num_hit++;
				}
				else 
				{
					ball.Draw(projection, modelview, window.size, window.stage, window.shader, current_time);
				}
				modelview = translate(modelview, -balls.at(i).getPostion());
			}

			if (window.num_balls - window.num_hit != window.num_remaining)
			{
				window.num_remaining = window.num_balls - window.num_hit;
				if (window.num_balls >= 10)
					window.num_remaining--;
				ostringstream convert3;
				ostringstream convert2;
				convert3 << window.num_remaining;
				if (window.num_balls >= 10)
					convert2 << window.num_balls - 1 << " + (1!)";
				else 
					convert2 << window.num_balls;
				displayNumRemaining = convert3.str();
				displayNumBalls = convert2.str();

				window.instructions.pop_back();
				window.instructions.pop_back();
				window.instructions.push_back("Targets remaining: " + displayNumRemaining + "/" + displayNumBalls);
				window.instructions.push_back("Time played: " + display_current_time);

				if (window.num_remaining == 0 )
				{
					ostringstream convert4;
					window.stage++;
					debug_mode = 2;
					window.betweenLevels = true;
					setLevel();
					convert4.clear();
					convert4 << window.stage;
					displayLevel = convert4.str();
					window.instructions.pop_back();
					window.instructions.pop_back();
					window.instructions.pop_back();
					window.instructions.push_back("Level: " + displayLevel);
					window.instructions.push_back("Targets remaining: " + displayNumRemaining + " / " + displayNumBalls);
					window.instructions.push_back("Time played: " + display_current_time);
				}
			}

			modelview = translate(modelview, vec3(0.0f, -window.ball_radius, 0.0f));
			for (int i = 0; i < (int)boxes.size(); i++)	//places the desired number of obstacles on field
			{
				modelview = translate(modelview, boxes.at(i).getPostion());	//places in random location
				box.Draw(projection, modelview, window.size, window.stage, window.shader);
				modelview = translate(modelview, -boxes.at(i).getPostion());
			}


			if (!window.gameStart) //Display start screen
			{
				modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f));
				modelview = scale(modelview, vec3(3.0f, 2.0f, 3.0f));
				screen.DrawScreen(projection, modelview, window.size, fbo, 1); //Display intro screen 
			}

			if (window.betweenLevels) //Display next level screen
			{
				modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f));
				screen.DrawScreen(projection, modelview, window.size, fbo, 2);
			}

			if (window.gameOver) //Display losing screen
			{
				modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f));
				screen.DrawScreen(projection, modelview, window.size, fbo, 3);
			}

			if (window.gameWon) //Display winning screen
			{
				modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f));
				screen.DrawScreen(projection, modelview, window.size, fbo, 4);
			}

		}
		window.instructions.pop_back();
		window.instructions.push_back("Time played: " + display_current_time);

		//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		DisplayInstructions();

		DisplayCursor();

		//display the minimap
		if (window.minimap)
			DisplayFunc2();

		//Display the clock
		if (window.clock_on)
			DisplayFuncClock2();

		if (window.hit_something) // display a cracked screen if hit something
		{
			DisplayFuncCrack();
		}

		window.hit_something = false; //reset to not show cracked screen

	}

	//glFlush();
	glutSwapBuffers();
	glutPostRedisplay(); // FPS
}
Пример #4
0
void Vectored_Interrupt(int button){
	char cString[4], currDiffString[4];
	//GLCD_Clear(White);                    /* Clear graphical LCD display        */
	GLCD_SetBackColor(Blue);
	GLCD_SetTextColor(White);
	
	switch(button){
		case USER_BUTTON:

				//GLCD_DisplayString(0, 0, __FI, "< --User Button -- >");
				switch(currentState) {
					case WELCOME_SCREEN: // If on the welcome screen, set up difficulty screen
						GLCD_Clear(White);
						if(currentDifficulty == 0){
							currentDifficulty = 1;
						}
						updateNextDifficulty(nextDifficulty);
						DisplayInstructions();
						DrawBarGraph(BAR_X,BAR_Y,currentDifficulty * 20,BAR_HEIGHT,BAR_VALUE);
						
						currentState = DIFFICULTY_SCREEN;
						
					break;
						
					case DIFFICULTY_SCREEN: // Transition to Question Screen
						
						updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty);
					
						currentDifficulty = nextDifficulty; // Set the difficulty
						
						currentState = QUESTION_SCREEN;
					
						questionScreen(); // Display the question screen
					
					
					break;
					
					case QUESTION_SCREEN: // Question Screen uses countdown timer - no inputs
						
					break;
					
					case ANSWER_SCREEN:
						
						//answerScreen();
					
						currentState = MARKING_SCREEN; // Mark the users answer
					break;
					

					
					case MARKING_SCREEN: // Mark the users answer attempt
						markAnswer();
					
						currentDifficulty = nextDifficulty; // Set the difficulty
					
						currentState = NEXT_QUESTION;
					
					break;
					
					case NEXT_QUESTION: // Move on to next question
						
						currentDifficulty = nextDifficulty; // Set the difficulty
						currentState = QUESTION_SCREEN;
						questionScreen(); // Display the question screen

					
					break;
					
			};
						
		
		
				//GLCD_DisplayString(6, 0, __FI, GenerateRandomString(5));
				
				//doTone = ~doTone;
			break;
		
		case JOYSTICK_SELECT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK Select -->");
				// Left available for future program improvements
			break;
		
		case JOYSTICK_UP:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK UP   -- >");
				
				inputAnswer(JOYSTICK_UP);
			break;
		
		case JOYSTICK_DOWN:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK DOWN -- >");
				
				inputAnswer(JOYSTICK_DOWN);
			break;
		
		case JOYSTICK_RIGHT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK RIGHT-- >");
				
				inputAnswer(JOYSTICK_RIGHT);
			break;
		
		case JOYSTICK_LEFT:
				//GLCD_DisplayString(0, 0, __FI, "< --JSTK LEFT -- >");
				
				inputAnswer(JOYSTICK_LEFT);
			break;
		
		case POTENTIOMETER_TURNED:
			  //sprintf(cString, "%02d", c);
		
			switch(currentState) {
				case DIFFICULTY_SCREEN:
					nextDifficulty = (c / 3) + 1;
									
					nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty;
				
					sprintf(currDiffString, "%1d", nextDifficulty);
					//updateScoreAndDifficulty(currentScore, currDifficulty, nextDifficulty);
					updateNextDifficulty(nextDifficulty);
					DrawBarGraph(BAR_X,BAR_Y,nextDifficulty * 20,BAR_HEIGHT,BAR_VALUE);
					//GLCD_SetBackColor(Red);
				break;
				
				case WELCOME_SCREEN:
					
				break;
				
				
				default:
					nextDifficulty = (c / 3) + 1;
									
					nextDifficulty = nextDifficulty > 5 ? 5 : nextDifficulty;
					sprintf(currDiffString, "%1d", nextDifficulty);
					
					updateScoreAndDifficulty(currentScore, currentDifficulty, nextDifficulty);
					
					
				break;
			}		
					
			break;
		
		default:
			break;
	}
}