Пример #1
0
/*
 the choice function which calles the function to display the I
 */
void choice(){
    
    glClear(GL_COLOR_BUFFER_BIT);

    if (filled == 0)
        displayFan();
    else if (filled ==1)
        displaySolid();
    
	glutSwapBuffers();

}
Пример #2
0
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
	srand((unsigned)time(0));		//	time used to help randomize spheres
	//set properties of the surface material
	GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };  //gray
	GLfloat mat_diffuse[] = { 0.6f, 0.6f, 0.6f, 1.0f };
	GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	GLfloat mat_shininess[] = { 50.0f };
	glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	// set the light source properties
	GLfloat lightIntensity[] = { 0.7f, 0.7f, 0.7f, 1.0f };
	GLfloat light_position[] = { 2.0f, 6.0f, 3.0f, 0.0f };
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);

	glMatrixMode(GL_PROJECTION);	// set the view volume (perspective)
	glLoadIdentity();
	gluPerspective(60, 1.5, 0.3, 50); //view angle, Aspect ratio, Near plane, Far plane

	glMatrixMode(GL_MODELVIEW);		// set the camera
	glLoadIdentity();
	gluLookAt(3, 3, 0, 2.5, 2.5, 10, 2.5, 10.0, 2.5);	//	eye (3,3,0); look at reference (2.5, 2.5, 10); up (2.5, 10, 2.5) 

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// clear the screen
	GLintPoint spheres[12];
	for (int i = 0; i < 12; i++)	//draw initial spheres
	{
		spheres[i].x = (rand() % 10);		//	randomizing initial values for x,y,z of starting location
		spheres[i].y = (rand() % 10);
		spheres[i].z = ((rand() % 50) + 1);

		spheres[i].a = ((rand() % 10) + 1) / 10.0;			//randomize float numbers 1-10, then divide by 10 to get decimal
		spheres[i].b = ((rand() % 10) + 1) / 10.0;			//used to create random 3 floats for color
		spheres[i].c = ((rand() % 10) + 1) / 10.0;

		GLfloat mat_ambient[] = { spheres[i].a, spheres[i].b,spheres[i].c, 1.0f };
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		juice[i] = spheres[i];		//insert initial values into shared array
		sphere(spheres[i].x, spheres[i].y, spheres[i].z, 0.1, 15, 15);
	}

	displaySolid();		//  call to function to move and recreate spheres
}
Пример #3
0
/******************************************************
* PONG
* DESCRIPTION: JConsole2 Portable implementation of pong
* Created: 8/28/2013
******************************************************/
void Pong(char autoAi)
{
   char hit = 0;
   char pong_ball_start = 0;
   unsigned int userScore = 0;
   unsigned int compScore = 0;
   unsigned int highScore = EEProm_Read_16(pongHighScore);
   unsigned int ballSpeed = PONG_INITIALBALLSPEED;
   struct Paddle playerPaddle;
   struct Paddle aiPaddle;
   struct Solid ball;
   LcdClear();

   //Construct game objects
   constructPaddle2(&aiPaddle, 74, 1, 10);
   constructPaddle2(&playerPaddle, 7, 1, 10);
   displayPaddle(&playerPaddle, 0);
   displayPaddle(&aiPaddle, 0);
   displayPongScore(&userScore, &compScore);
   reset(&ball, 15, 1, 3, 3, 1);

   //Start timers
   StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
   StartTimer(1, ballSpeed);  //Move player timer

   for (;;)
   {
	  if (CheckTimer(0))
	  {
		  if (GetDown())
		  {
		     paddle_moveDown(&playerPaddle);
		  }
		  else if (GetUp())
		  {
			  paddle_moveUp(&playerPaddle);
		  }
		  else if (GetEnterButton()) //Pause
		  {
			 if (Pause(showPongScore, userScore,  compScore, highScore) == 1)
			 {
			     return;
			 }
			 displayPaddle(&playerPaddle, 0);
			 displayPaddle(&aiPaddle, 0);
			 displaySolid(&ball, 0);
			 displayPongScore(&userScore, &compScore);
		  }
		  StartTimer(0, PONG_PLAYERMOVETIME);  //Move player timer
	  }
      if (CheckTimer(1))
      {
         //If ball moves and hits a wall, make a sound
         if (autoMoveSolid(&ball) > 1)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
         }
         aiMove(&aiPaddle, &ball); //Move computer players paddle
         if (autoAi == 1)
         {
            aiMove(&playerPaddle, &ball);
         }
         hit = checkForHit(&aiPaddle, &ball) + checkForHit(&playerPaddle, &ball);   //Check to see if ball hit either paddle
         if (hit != 0)
         {
        	 SendData(SOUND_BLOCK_DESTROYED);
        	displayPongScore(&userScore, &compScore);
        	if (ballSpeed > 10)
        	{
        	   ballSpeed = ballSpeed - 1;
        	}
         }
         //Ball hit on players side
         if (ball.xLocation == 1)
         {
            compScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
         }
         //Ball hit on computers side
         else if (ball.xLocation == 76)
         {
            userScore++;
            displayPongScore(&userScore, &compScore);
            displayPaddle(&playerPaddle, 0);
            displayPaddle(&aiPaddle, 0);
            randomBallStart(&ball, &pong_ball_start);
            if (userScore > highScore)
            {
               highScore = userScore;
               EEProm_Write_16(highScore, pongHighScore);
            }
         }
         StartTimer(1, ballSpeed);  //Move player timer
      }
   }

}
Пример #4
0
/**********************************************************
* DEBRIS GAME
* DESCRIPTION: This is a game where you need to shoot blocks
**********************************************************/
void Debris(void)
{
   char xMoveStart = 1;
   char fireIndex = 0;
   char moveYStart = 0;
   char yPosStart = 1;
   char index = 0;
   char index2 = 0;
   char jetHitCheck = 1;
   char lastCheck = 0;
   char numShots = 0;
   char yStart = 1;
   unsigned int ballSpeed = DEBRIS_DEBRISMOVERATE;
   unsigned int health = 47;
   unsigned int ballsDestroyed = 0;
   unsigned int highScore = EEProm_Read_16(debrisHighScore_Addr);
   struct Solid balls[DEBRIS_MAXDEBRIS];
   struct Fire ammo[DEBRIS_MAXPROJECTILES];
   struct Jet jet;

   if (health == 0)
   {
      health = 47;
   }

   //Assign pointers to allocated objects
   for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
   {
      balls[index].enabled = 0; //Balls start disabled
   }
   LcdClear();

   //Initialize game objects
   constructJet(&jet, 15, 2);

   //Initialize balls
   reset(&balls[0], 80, 4, 1, 1, 1);
   reset(&balls[1], 60, 0, 3, 2, 1);
   reset(&balls[2], 70, 3, 1, 1, 1);
   reset(&balls[3], 60, 2, 3, 2, 1);
   reset(&balls[4], 80, 1, 1, 1, 1);
   display_jet(&jet, 0);
   DisplayHealth(health, 0);

   //Start Timers
   StartTimer(0, DEBRIS_USERMOVERATE_MS);     //Move player timer
   StartTimer(1, DEBRIS_RATEOFFIRE_MS);       //Fire timer
   StartTimer(2, DEBRIS_PROJECTILESPEED_MS);  //Fire move timer
   StartTimer(3, ballSpeed);                  //Move balls

   //Enter game loop
   for (;;)
   {
	  //Check user move button
	  if (CheckTimer(0))
	  {
		  if (GetEnterButton()) //User wants to pause the game
		  {
			  if (Pause(showJetScore, ballsDestroyed,  health, highScore) == 1)
			  {
				  return;
			  }
			  display_jet(&jet, 0);
			  DisplayHealth(health, 0);
		  }
		  else if (GetLeft()) //Left button is being pressed
		  {
			  jet_moveLeft(&jet, 0);
		  }
		  else if (GetRight())
		  {
			  jet_moveRight(&jet, 0);
		  }
		  if (GetUp())
		  {
			  jet_moveUp(&jet);
		  }
		  else if (GetDown())
		  {
			  jet_moveDown(&jet);
		  }
		  StartTimer(0, DEBRIS_USERMOVERATE_MS); //Reset this timer
	  }
      //Check fire buttons
      if (CheckTimer(1)) //Now we can fire
      {
    	  if (GetFire()) //User took the chance to fire
    	  {
             if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
             numShots++;
             startFire(&ammo[fireIndex], &jet, 0);
             StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
             fireIndex++;
             SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetSecFire()) //Shockwave cannon
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    	     startFire(&ammo[fireIndex], &jet, 2);
    		 StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300); //Restart the fire timer.
    		 numShots++;
    		 fireIndex++;
    		 SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightFire()) //Fire Reverse
    	  {
    		 if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		 startFire(&ammo[fireIndex], &jet, 1);
    	     StartTimer(1, DEBRIS_RATEOFFIRE_MS); //Restart the fire timer.
    	     numShots++;
    	     fireIndex++;
    	     SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
    	  else if (GetRightSecFire()) //Reverse Shockwave cannon
    	  {
    		  if (fireIndex == DEBRIS_MAXPROJECTILES){fireIndex = 0;}
    		  startFire(&ammo[fireIndex], &jet, 3);
    	      StartTimer(1, DEBRIS_RATEOFFIRE_MS + 300);
    	      numShots++;
    	      fireIndex++;
    	      SendData(SOUND_FIRE_PROJECTILE); //Fire sound
    	  }
      }
      //Moves the weapons fire
      if (CheckTimer(2))
      {
          //Check each ammo value to see if it hit a ball
          for (index = 0; index < DEBRIS_MAXPROJECTILES; index++)
          {
             if (ammo[index].enabled == 1) //This gives the game a performance boost but can cause inconsistant ball speeds
             {
                if (autoMove(&ammo[index]) == 1)
                {

                }
                if (lastCheck == 0)
                {
             	  lastCheck = 1;
                   //Check each bullet to see if it hit a ball
                   for (index2 = 0; index2 < DEBRIS_MAXDEBRIS; index2++)
                   {
                      //If a ball is hit, reset it so it starts over again.
             	     if (fire_checkHit(&ammo[index], &balls[index2]) == 1)//ammo[index].fireOutput == 1)
                      {
             	    	SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
             	        balls[index2].enabled = 0;
             	        displaySolid(&balls[index2], 1);
                         if (ammo[index].weapon != 2 && ammo[index].weapon != 3)
                         {
                 	       ammo[index].enabled = 0;
                 	       displayFire(&ammo[index], 1);
                         }
                         //Ball speed increases every time 3 balls are dispatched
                         if (ballsDestroyed % 3 == 0 && ballSpeed > 15)
                         {
                         	ballSpeed--;
                         }
                         changeBallStart(&balls[index2], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                         ballsDestroyed++;
                         if (ballsDestroyed > highScore)
                         {
                         	highScore = ballsDestroyed;
                         	EEProm_Write_16(debrisHighScore_Addr, highScore);
                         }
                      }
                   }
                }
                else
                {
             	   lastCheck = 0;
                }
             }
          }
         StartTimer(2, DEBRIS_PROJECTILESPEED_MS);
      }
      //Move the balls
      if (CheckTimer(3))
      {
          for (index = 0; index < DEBRIS_MAXDEBRIS; index++)
          {
         	if (balls[index].enabled == 1) //Gives a small performance boost at the cost of ball speed consistancy
         	{
         	   autoMoveSolid(&balls[index]);
         	   if (jetHitCheck == 0)
         	   {
                   //Ball hits the jet
         		  jetHitCheck = 1;
                   if (jet_checkHit(&jet, &balls[index]) != 0x00)
                   {
                	  SendData(SOUND_BLOCK_DESTROYED); //Block hit sound
                      balls[index].enabled = 0;
                      displaySolid(&balls[index], 1);
                      display_jet(&jet, 0);
         	          health--;
         	         DisplayHealth(health, 0);
         	         //Jet was destroyed
         	         if (health == 0)
         	         {
         	        	display_jet(&jet, 1);
         	    	    constructJet(&jet, 15, 2);
         	    	    health = 47;
         	    	    ballsDestroyed = 0;
         	    	    display_jet(&jet, 0);
         	         }
         	         changeBallStart(&balls[index], &moveYStart, &yPosStart, &xMoveStart, &yStart);
                  }
         	   }
         	   else
         	   {
         		   jetHitCheck = 0;
         	   }
             }
         }
         StartTimer(3, ballSpeed);
      }
   }
}