예제 #1
0
void GameController::displayGamePlay()
{
	glEnable(GL_DEPTH_TEST); // must be done each time before displaying graphics or gets disabled for some reason
	glLoadIdentity();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);

	for (int i = NUM_LAYERS - 1; i >= 0; --i)
	{
		std::set<GraphObject*> &graphObjects = GraphObject::getGraphObjects(i);

		for (auto it = graphObjects.begin(); it != graphObjects.end(); it++)
		{
			GraphObject* cur = *it;
			if (cur->isVisible())
			{
				cur->animate();

				double x, y, gx, gy, gz;
				cur->getAnimationLocation(x, y);
				convertToGlutCoords(x, y, gx, gy, gz);

				SpriteManager::Angle angle;
				switch (cur->getDirection())
				{
				case GraphObject::up:
					angle = SpriteManager::face_up;
					break;
				case GraphObject::down:
					angle = SpriteManager::face_down;
					break;
				case GraphObject::left:
					angle = SpriteManager::face_left;
					break;
				case GraphObject::right:
				case GraphObject::none:
				default:
					angle = SpriteManager::face_right;
					break;
				}

				int imageID = cur->getID();

				// the specialized Dirt plotting is an optimization to deal with the background Dirt, which requires a lot of horsepower to plot
				if (imageID == IID_DIRT)
					drawDirt(gx, gy, gz, cur->getSize());
				else
					m_spriteManager.plotSprite(imageID, cur->getAnimationNumber() % m_spriteManager.getNumFrames(imageID), gx, gy, gz, angle, cur->getSize());
			}
		}
	}

	drawScoreAndLives(m_gameStatText);

	glutSwapBuffers();
}
예제 #2
0
void GameController::displayGamePlay()
{
	glEnable(GL_DEPTH_TEST); // must be done each time before displaying graphics or gets disabled for some reason
	glLoadIdentity();
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	gluLookAt(0, 0, 0, 0, 0, -1, 0, 1, 0);
	
	std::set<GraphObject*>& graphObjects = GraphObject::getGraphObjects();
	for (auto it = graphObjects.begin(); it != graphObjects.end(); it++)
	{
		GraphObject* cur = *it;
		if (cur->isVisible())
		{
			cur->animate();

			double x, y, gx, gy, gz;
			cur->getAnimationLocation(x,y);
			convertToGlutCoords(x,y, gx, gy, gz);
			
			SpriteManager::Angles angle;
			switch (cur->getDirection())
			{
				case GraphObject::up:
					angle = SpriteManager::face_up;
					break;
				case GraphObject::down:
					angle = SpriteManager::face_down;
					break;
				case GraphObject::left:
					angle = SpriteManager::face_left;
					break;
				default:
				case GraphObject::right:
				case GraphObject::none:
					angle = SpriteManager::face_right;
					break;
			}

			int imageID = cur->getID();
			int frame = cur->getAnimationNumber() % m_spriteManager.getNumFrames(imageID);
			m_spriteManager.plotSprite(imageID, frame, gx, gy, gz, angle);
		}
	}
	
	drawScoreAndLives(m_gameStatText);
	
	glutSwapBuffers();
}