Esempio n. 1
0
void MainMenu::Display()
{
   OpenGL& opengl = OpenGL::GetInstance();

   DisplayStars();

   // Draw logo and menu items
   startOpt.Display(selOption == optStart, bigness, fade);
   scoreOpt.Display(selOption == optScore, bigness, fade);
   optionsOpt.Display(selOption == optOptions, bigness, fade);
   exitOpt.Display(selOption == optExit, bigness, fade);

   int title_x = (opengl.GetWidth() - titleImage.GetWidth()) / 2;
   int title_y = 100;
   titleImage.Draw(title_x, title_y, 0.0, 1.0, fade);

   // Draw some hint texts
   const int numhints = 7;
   const char* hints[] = {
      i18n("Use the arrow keys to rotate the ship"),
      i18n("Press the up arrow to fire the thruster"),
      i18n("Smaller landing pads give you more points"),
      i18n("Press P to pause the game"),
      i18n("Press escape to self destruct"),
      i18n("You can only land safely when then speed bar is green"),
      i18n("Collect the spinning rings to unlock the landing pads")
   };

   if (m_hintTimeout <= 0.0f) {
      hintidx = rand() % numhints;
      m_hintTimeout = HINT_DISPLAY_TIME;
   }
   else
      m_hintTimeout -= opengl.GetTimeScale();

   int x = (opengl.GetWidth() - hintFont.GetStringWidth(hints[hintidx])) / 2;
   int y = opengl.GetHeight() - 120;
   hintFont.SetColour(0.0f, 1.0f, 0.0f, fade);
   hintFont.Print(x, y, hints[hintidx]);
}
Esempio n. 2
0
void DisplayHandler () // display callback function
{
	if (bRotate) 
	{
		fCameraAngle[0] += 1.0 ;
		fCameraAngle[2] += 1.0 ;
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
	glLoadIdentity() ;

	SetCamera() ;

	if (!bPause)
	{
		GLfloat fTempX = GLfloat(iLastMouseX) / GLfloat(iWinWidth) ;
		GLfloat fTempY = GLfloat(iLastMouseY) / GLfloat(iWinHeight) ;
		GLfloat fFixedX = (Player.ptLocation.dX - 8.65) / -17.3 ;
		GLfloat fFixedZ = (Player.ptLocation.dZ - 8.65) / -17.3 ;
		if (bRightMouseDown)
		{
			if (!(fFixedX + 0.02 > fTempX && fFixedX - 0.02 < fTempX))
			{
				if (fFixedX > fTempX)
				{
					Player.ptLocation.dX += 0.1 ;
					if (Player.ptAngle.dZ > -20) 
						Player.ptAngle.dZ -= 5.0 ;
				} else
				{
					Player.ptLocation.dX -= 0.1 ;
					if (Player.ptAngle.dZ < 20) 
						Player.ptAngle.dZ += 5.0 ;
				}
			} else
			{
				if (Player.ptAngle.dZ < 0) Player.ptAngle.dZ += 5.0 ;
				else if (Player.ptAngle.dZ > 0)	Player.ptAngle.dZ -= 5.0 ;
			}
			if (!(fFixedZ + 0.1 > fTempY && fFixedZ - 0.02 < fTempY))
			{
				if (fFixedZ > fTempY)
				{
					Player.ptLocation.dZ += 0.1 ;
				} else 
				{
					Player.ptLocation.dZ -= 0.1 ;
				}
			}
		} else Player.ptAngle.dZ = 0 ;

		if (randp() > 0.98) AddPlanet() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;
		AddStar() ;

		if (/*!bExplode && */iCount % 15 == 0) SpawnEnemy() ;

		if (!bExplode && bAutofire && iCount % 4 == 0) FireShot(&Player, pPlayerShots) ;

		iCount ++ ;

	}
	
	DisplayStars() ;
	DisplayPlanets() ;
	DisplayEnemies() ;

	DisplayShots(pPlayerShots) ;
	DisplayShots(pEnemyShots) ;

	if (bExplode && !bPause)
	{
		if (iCount == 0) 
		{
			printf("Game over\n") ;
			MakeExplosion(Player.ptLocation, 1000) ;
		}
	} else 
	{
		if (iCount % 4)
		{
			Particle *pNew = new Particle ;
			pNew->ptLocation.dX = Player.ptLocation.dX + randp() * 0.5 - 0.25;
			pNew->ptLocation.dY = Player.ptLocation.dY + 0.3 * randp() ;
			pNew->ptLocation.dZ = Player.ptLocation.dZ - 1.5 + 0.2 * randp() ;
			pNew->ptVelocity.dX = 0 ;
			pNew->ptVelocity.dY = 0 ;
			pNew->ptVelocity.dZ = -0.2 ;
			pNew->ptColor.dX = 0.98 ;
			pNew->ptColor.dY = 0.59 + 0.3 * randp() - 0.15 ;
			pNew->ptColor.dZ = 0.01 ;
			pNew->dAlpha = 0.7 ;
			pNew->dMass = 1 ;
			pNew->dLife = 7 * randp() + 3 ;
			pNew->ptAcceleration = 0 ;
			Particles.AddBack(pNew) ;
		}

		Player.Display() ;
	}

	LinkedListNode<Particle> *pTravParticles = Particles.pHead ;
	LinkedListNode<Particle> *pTempParticle ;
	
	while (pTravParticles != 0)
	{
		pTravParticles->pValue->dLife -- ;
		if (pTravParticles->pValue->dLife <= 0)
		{
			pTempParticle = pTravParticles ;
			pTravParticles = pTravParticles->pNext ;
			Particles.Remove(pTempParticle, true) ;
		} else
		{
			pTravParticles->pValue->Apply(0.9) ;
			
			DisplayParticle(pTravParticles->pValue) ;
			
			pTravParticles = pTravParticles->pNext ;
		}
	}
	
		
	glFinish() ;
	glutSwapBuffers() ;
	glutPostRedisplay() ;
}