示例#1
0
	void ObstacleFactory::update( float time )
	{
		
		
		Obstacle* b;
		std::string name;

		for (ObstacleIterator ei = ObstacleList.begin(); ei != ObstacleList.end(); ){
			b = *ei;
			b->update(time);
			ei++;
			if(b->die)
			{
				delete b;
				b = 0;
			}


			
			name = b->getName();
			sillyRotation(time, b->getSceneNode());

			if(hit)
				sillyHitCamera(time, b->getSceneNode());

			
		}


		if(!hit)
			debug->setText("false");

		//resetPath();
		//ObstacleList.clear();
	}
示例#2
0
void updateGame(void)
{
	// Get game time
	timer.tick();
	GameTime gameTime = timer.getGameTime();

	// Get input
	keyboard.getState(currState);
	gameInput();

	if (!paused && !won)
	{
		// Update game objects
		ball.update(gameTime, 0, window.height);

		player.update(gameTime, 0, window.height);
		ai.update(gameTime, 0, window.height, ball.position);

		GLuint halfPoints = static_cast<GLuint>(POINTS_TO_WIN * 0.5f);
		if (playerScore >= halfPoints || aiScore >= halfPoints)
		{
			// Increase obstacle speed as the stakes heighten
			GLuint higherScore = std::max(playerScore, aiScore);
			GLuint diff = POINTS_TO_WIN - higherScore;
			float t = 1.0f / diff;

			float minSpeed = 200.0f;
			float maxSpeed = 600.0f;

			float speed = Math::lerp(minSpeed, maxSpeed, t);

			o1.update(gameTime, 125.0f, 475.0f, speed);
			o2.update(gameTime, 125.0f, 475.0f, speed);
		}

		// Resolve collisions
		if(ball.position.distanceToSquared(player.position) <= 50.0f * 50.0f)
		{
			player.checkCollisions(ball);
		}
		else if(ball.position.distanceToSquared(ai.position) <= 50.0f * 50.0f)
		{
			ai.checkCollisions(ball);
		}
		else if(ball.position.distanceToSquared(o1.position) <= 50.0f * 50.0f)
		{
			o1.checkCollisions(ball);
		}
		else if(ball.position.distanceToSquared(o2.position) <= 50.0f * 50.0f)
		{
			o2.checkCollisions(ball);
		}

		// Scoring
		checkBall();

		// Save input state
		prevState = currState;

		// Force game to redisplay
		glutPostRedisplay();
	}
}