Ejemplo n.º 1
0
void PlayNRounds(int n){
#ifdef _WIN32
    system("cls");
#elif defined(__linux__)
    system("clear");
#endif
    int score;
    Game myGame;
    bool isGameOver;
    dir_e dir;

    gotoXY(5,0);
    std::cout<<"Previous";
    gotoXY(35,0);
    std::cout<<"Current (Hint: "<<myGame.getHint()<<")";
    myGame.printGrid(35,2);

    if(myGame.isGameOver(score))  myGame.reset();

    Grid myGrid;
    for(int i = 0;i < n;i++){    
        isGameOver = false;
        while(!isGameOver){
            //while((dir = getDirFromKeyboard()) == INVALID);
			myGame.getCurrentGrid(myGrid);
			dir=computeDir(myGrid, myGame.getHint());
            gotoXY(5,10);
            std::cout<<dirToStr(dir);
            myGame.printGrid(5,2);
          
            myGame.insertDirection(dir);
            gotoXY(50,0);
            std::cout<<myGame.getHint();
            isGameOver = myGame.isGameOver(score);
            myGame.printGrid(35,2);
            
       }
        myGame.printGrid(35,2);
        if(i < n - 1)  myGame.reset();
        gotoXY(0,15); 
        printf("  Round:    %d      \n", i+1);
        printf("  Score:    %d      \n", score);
 
    }
}
Ejemplo n.º 2
0
void display() {
    computePos(deltaForwardMove, deltaSideMove);
    if(deltaAnglex){
        computeDir(deltaAnglex, deltaAngley);
    }
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt(camx,     1.0f,   camz,
              camx+lx,  1.0+ly,   camz+lz,
              0.0f,     1.0f,   0.0f);
    makelighting();
    makewalls();
    
    // make balls
    for (int i = 0; i < numballs; i++) {
        makeball(balls[i]);
    }
    makecubes();
    glutSwapBuffers();
}
void renderScene(void) {

	if (deltaMove)
		computePos(deltaMove);
	if (deltaAngle)
		computeDir(deltaAngle);

	// Clear Color and Depth Buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Reset transformations
	glLoadIdentity();
	// Set the camera
	gluLookAt(	x, 1.0f, z,
				x+lx, 1.0f,  z+lz,
				0.0f, 1.0f,  0.0f);

	// Draw ground

	glColor3f(0.9f, 0.9f, 0.9f);
	glBegin(GL_QUADS);
		glVertex3f(-100.0f, 0.0f, -100.0f);
		glVertex3f(-100.0f, 0.0f,  100.0f);
		glVertex3f( 100.0f, 0.0f,  100.0f);
		glVertex3f( 100.0f, 0.0f, -100.0f);
	glEnd();

	// Draw 36 SnowMen

	for(int i = -3; i < 3; i++)
		for(int j=-3; j < 3; j++) {
			glPushMatrix();
			glTranslatef(i*10.0,0,j * 10.0);
			drawSnowMan();
			glPopMatrix();
		}

	glutSwapBuffers();
}
void display(void)
{

   GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
   GLfloat sun_ambient[] = { 1.0, 1.0, 0.0, 1.0 };
   GLfloat mat_ambient_color[] = { 0.8, 0.8, 0.2, 1.0 };
   GLfloat sun_diffuse[] = { 0.6, 0.6, 0.0, 1.0 };
   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat no_shininess[] = { 0.0 };
   GLfloat low_shininess[] = { 5.0 };
   GLfloat sun_shininess[] = { 70.0 };
   GLfloat sun_emission[] = {0.3, 0.3, 0.0, 0.0};

	GLfloat mercury_ambient[] = { 0.6, 0.1, 0.0, 1.0 };
	GLfloat mercury_diffuse[] = { 0.6, 0.1, 0.0, 1.0 };
	GLfloat mercury_shininess[] = { 30.0 };
    GLfloat mercury_emission[] = {0.2, 0.2, 0.0, 0.0};

	GLfloat venus_ambient[] = { 0.6, 0.3, 0.0, 1.0 };
	GLfloat venus_diffuse[] = { 0.6, 0.3, 0.0, 1.0 };
	GLfloat venus_shininess[] = { 30.0 };
    GLfloat venus_emission[] = {0.2, 0.3, 0.0, 0.0};

	GLfloat earth_ambient[] = { 0.2, 0.2, 0.55, 1.0 };
	GLfloat earth_diffuse[] = { 0.2, 0.2, 0.55, 1.0 };
	GLfloat earth_shininess[] = { 40.0 };
    GLfloat earth_emission[] = {0.1, 0.1, 0.45, 0.0};

	GLfloat mars_ambient[] = { 0.75, 0.2, 0.02, 1.0 };
	GLfloat mars_diffuse[] = { 0.75, 0.2, 0.02, 1.0 };
	GLfloat mars_shininess[] = { 30.0 };
    GLfloat mars_emission[] = {0.3, 0.2, 0.0, 0.0};

	GLfloat jupitor_ambient[] = { 0.9, 0.7, 0.3, 1.0 };
	GLfloat jupitor_diffuse[] = { 0.9, 0.7, 0.3, 1.0 };
	GLfloat jupitor_shininess[] = { 20.0 };
	GLfloat jupitor_emission[] = {0.1, 0.1, 0.0, 0.0};

	GLfloat saturn_ambient[] = { 0.6, 0.6, 0.4, 1.0 };
	GLfloat saturn_diffuse[] = { 0.6, 0.6, 0.4, 1.0 };
	GLfloat saturn_shininess[] = { 20.0 };
	GLfloat saturn_emission[] = {0.2, 0.2, 0.0, 0.0};

	GLfloat uranus_ambient[] = { 0.4, 0.6, 0.8, 1.0 };
	GLfloat uranus_diffuse[] = { 0.4, 0.6, 0.8, 1.0 };
	GLfloat uranus_shininess[] = { 20.0 };
	GLfloat uranus_emission[] = {0.1, 0.2, 0.5, 0.0};

	GLfloat neptune_ambient[] = { 0.4, 0.0, 0.6, 1.0 };
	GLfloat neptune_diffuse[] = { 0.4, 0.0, 0.6, 1.0 };
	GLfloat neptune_shininess[] = { 20.0 };
	GLfloat neptune_emission[] = {0.1, 0.1, 0.2, 0.0};

	GLfloat pluto_ambient[] = { 0.4, 0.1, 0.7, 1.0 };
	GLfloat pluto_diffuse[] = { 0.4, 0.1, 0.7, 1.0 };
	GLfloat pluto_shininess[] = { 20.0 };
	GLfloat pluto_emission[] = {0.0, 0.2, 0.3, 0.0};

	
	if (deltaMove)
		computePos(deltaMove);
	if (deltaAngle)
		computeDir(deltaAngle);

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glColor3f (1.0, 1.0, 1.0);

   //glRotatef(5.0,1.0,0.0,0.0);

   glPushMatrix();
    gluLookAt(	x, 1.0f, z,
				x+lx, 1.0f,  z+lz,
				0.0f, 1.0f,  0.0f);

 	glRotatef(rotateScene,1.0,0.0,0.0);
	if(flag==1)
	displayPath();
	

	glPushMatrix();
		glMaterialfv(GL_FRONT, GL_AMBIENT, sun_ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, sun_diffuse);
		//glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
		glMaterialfv(GL_FRONT, GL_SHININESS, sun_shininess);
		glMaterialfv(GL_FRONT, GL_EMISSION, sun_emission);
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		gluSphere(sun,1.5,20,20);
		//glutSolidSphere(1.5, 20, 20);   /* draw sun */
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) mercuryRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, mercury_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mercury_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS, mercury_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, mercury_emission);
			glTranslatef (2.0, 0.0, 0.0);
			 glBindTexture(GL_TEXTURE_2D, texture[1]);
			 gluSphere(mercury,.2,20,18);
		glPopMatrix();
		if(mercuryRot>=360.0)
			mercuryRot=0.0;
	mercuryRot=mercuryRot+1.0 ;
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) venusRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, venus_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, venus_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS, venus_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, venus_emission);
			glTranslatef (4.0, 0.0, 0.0);
			 glBindTexture(GL_TEXTURE_2D, texture[2]);
			 gluSphere(venus,.4,20,18);
		glPopMatrix();
			venusRot=venusRot+.800;
			if(venusRot>=360.0)
			venusRot=0.0;
	glPopMatrix();

	glPushMatrix();
		glRotatef(rotateAstroid,0.0,1.0,0.0);
		makeAstroidBelt();
		rotateAstroid+=0.3;
	glPopMatrix();


	glPushMatrix();
		glRotatef ((GLfloat) earthRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, earth_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, earth_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,earth_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, earth_emission);
			glTranslatef (6.0, 0.0, 0.0);
			glBindTexture(GL_TEXTURE_2D, texture[3]); //earth
			 gluSphere(earth,.5,20,18);
			earthRot=earthRot+.5;
			if(earthRot>=360.0)
			earthRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) marsRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, mars_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mars_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,mars_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, mars_emission);
			glTranslatef (8.0, 0.0, 0.0);
			//glutSolidSphere(0.65, 20, 18); //mars
			glBindTexture(GL_TEXTURE_2D, texture[4]);
			 gluSphere(mars,.65,20,18);
			marsRot=marsRot+0.53;
				if(marsRot>=360.0)
			marsRot=0.0;
		glPopMatrix();		
	glPopMatrix();



	glPushMatrix();
		glRotatef ((GLfloat) jupitorRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
		glRotatef (90.0,1.0,0.0,0.0);
			glMaterialfv(GL_FRONT, GL_AMBIENT, jupitor_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, jupitor_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,jupitor_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, jupitor_emission);
			glTranslatef (10.0, 0.0, 0.0);
			//glutSolidSphere(0.8, 20, 18);  //jupiter
			glBindTexture(GL_TEXTURE_2D, texture[5]);
			 gluSphere(jupiter,.9,20,18);
			jupitorRot=jupitorRot+0.084;
				if(jupitorRot>=360.0)
			jupitorRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) saturnRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, saturn_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, saturn_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,saturn_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, saturn_emission);
			glTranslatef (12.0, 0.0, 0.0);
			circle(0.0,0.0,0.0,0.9);
			circle(0.0,0.0,0.0,0.85);
			circle(0.0,0.0,0.0,0.95);
			circle(0.0,0.0,0.0,1.0);
			circle(0.0,0.0,0.0,1.05);
			circle(0.0,0.0,0.0,1.10);
			circle(0.0,0.0,0.0,1.15);
			//glutSolidSphere(0.7, 20, 18);  //saturn
			glBindTexture(GL_TEXTURE_2D, texture[6]);
			gluSphere(saturn,.7,20,18);
			saturnRot=	saturnRot+	0.034;
			if(saturnRot>=360.0)
			saturnRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) uranusRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, uranus_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, uranus_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,uranus_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, uranus_emission);
			glTranslatef (14.0, 0.0, 0.0);
			glBindTexture(GL_TEXTURE_2D, texture[7]);
			gluSphere(uranus,.6,20,18);
			uranusRot=uranusRot+0.012;
				if(uranusRot>=360.0)
			uranusRot=0.0;
		glPopMatrix();		
	glPopMatrix();
	
	glPushMatrix();
		glRotatef ((GLfloat) neptuneRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, neptune_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, neptune_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,neptune_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, neptune_emission);
			glTranslatef (16.0, 0.0, 0.0);
		//	glutSolidSphere(0.3, 20, 18); //neptune
			glBindTexture(GL_TEXTURE_2D, texture[8]);
			gluSphere(neptune,.3,20,18);
			neptuneRot=neptuneRot+0.007;
				if(neptuneRot>=360.0)
			neptuneRot=0.0;
		glPopMatrix();
	glPopMatrix();

	glPushMatrix();
		glRotatef ((GLfloat) plutoRot, 0.0, 1.0, 0.0);
		glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
		glPushMatrix();
			glMaterialfv(GL_FRONT, GL_AMBIENT, pluto_ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, pluto_diffuse);
			glMaterialfv(GL_FRONT, GL_SHININESS,pluto_shininess);
			glMaterialfv(GL_FRONT, GL_EMISSION, pluto_emission);
			glTranslatef (18.0, 0.0, 0.0);
			//glutSolidSphere(0.3, 20, 18);  //pluto
			glBindTexture(GL_TEXTURE_2D, texture[9]);
			gluSphere(pluto,.3,20,18);
			plutoRot=plutoRot+0.004;
				if(plutoRot>=360.0)
			plutoRot=0.0;
		glPopMatrix();
	glPopMatrix();
	
   glFlush();
   glPopMatrix();
   skyBox();
   glutSwapBuffers();
}
Ejemplo n.º 5
0
void display()
{
    
    /*---------------------------------------Lighting ------------------------------------------------*/       
    typedef struct materialStruct { 
        float ambient[4]; 
        float diffuse[4]; 
        float specular[4]; 
        float emission[4];
        float m_amb[4];
        float m_diff[4]; 
        float m_spec[4] ;
        float shininess; 
    } materialStruct; 
    
    materialStruct redPlastic = { 
        {0.0, 0.0, 0.3, 1.0}, 
        {0.0, 0.4, 0.1, 1.0}, 
        {0.6, 0.6, 0.8, 1.0}, 
        {0.0, 0.0, 0.0, 0.0}, 
        {0.03, 0.22, 0.03, 1.0},
        {0.18, 0.77, 0.1, 1.0},
        {0.10, 0.41, 0.29, 1.0},
        50.0 
    }; 
    
    //  glEnable(GL_LIGHTING); 
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_pos);                   //First light point
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glLightfv(GL_LIGHT0, GL_AMBIENT, redPlastic.ambient);  
    glLightfv(GL_LIGHT0, GL_DIFFUSE, redPlastic.diffuse); 
    glLightfv(GL_LIGHT0, GL_SPECULAR, redPlastic.specular); 
    
    
    
    glEnable(GL_LIGHT1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_pos1);                  //Second Light point
    
    glLightfv(GL_LIGHT1, GL_AMBIENT, redPlastic.ambient);  
    glLightfv(GL_LIGHT1, GL_DIFFUSE, redPlastic.diffuse); 
    glLightfv(GL_LIGHT1, GL_SPECULAR, redPlastic.specular); 
    
    
    typedef struct materialStruct2 { 
        float ambient[4]; 
        float diffuse[4]; 
        float specular[4]; 
        float emission[4];
        float m_amb[4];
        float m_diff[4]; 
        float m_spec[4] ;
        float shininess; 
    } materialStruct2; 
    
    materialStruct2 redPlastic2 = { 
        {0.0, 0.0, 0.3, 1.0}, 
        {0.6, 0.1, 0.1, 1.0}, 
        {0.6, 0.6, 0.8, 1.0}, 
        {0.0, 0.0, 0.0, 0.0}, 
        {0.03, 0.02, 0.33, 1.0},
        {0.78, 0.17, 0.21, 1.0},
        {0.30, 0.11, 0.19, 1.0},
        50.0 
    }; 
    
    
    glEnable(GL_LIGHT2);
    glLightfv(GL_LIGHT2, GL_POSITION, light_pos2);                      //Third Light point
    
    glLightfv(GL_LIGHT2, GL_AMBIENT, redPlastic2.ambient);  
    glLightfv(GL_LIGHT2, GL_DIFFUSE, redPlastic2.diffuse); 
    glLightfv(GL_LIGHT2, GL_SPECULAR, redPlastic2.specular); 

    
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,  redPlastic2.ambient);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,  redPlastic2.diffuse);  
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  redPlastic2.specular);  
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS,  redPlastic2.shininess);  
    
	//clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();
    
    
    if (deltaMove)
		computePos(deltaMove);
	if (deltaAngle)
		computeDir(deltaAngle);
    
    //gluLookAt(0, 30, 70, 0, 0, 0, 0, 1, 0);
	gluLookAt(eye[0],eye[1],eye[2],eye[0]+point[0],eye[1],eye[2]+point[2],0,1,0);
    camerapos [0] = eye[0];
    camerapos[2] = eye[2];
	//optionally draw the axis
    //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, "SPACE Helicopter PRO");
	//drawAxis();
    drawstar();
    	

	drawRocks();
    
    glPushMatrix();
    
    /*---------------------------------------Solar system-----------------------------------------*/

    
    //Venus
    
    glRotatef(ang/200, 0, 1, 1);
    
    glTranslatef(100, 0, 0);
    
    glColor3f(1, 0, 0);
    
    glScalef(2, 2, 2);
    
    drawsphere();
    
    
    
    glPopMatrix();
    
    glPushMatrix();
    
    //Earth
    
    glRotatef(ang/250, 0, 1, 1);
    
    glTranslatef(150, 0, 0);
    
    glColor3f(0, 0, 1);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    
    //moon
    
    glRotatef(ang/80, 0, 1, 1);
    
    glTranslatef(75, 0, 0);
    
    glColor3f(1, .5, .5);
    
    glScalef(1, 1, 1);
    
    drawsphere();
    
    
    
    glPopMatrix();
    
    glPushMatrix();
    
    
    
    //Mars
    
    glRotatef(ang/500, 0, 1, 0);
    
    glTranslatef(200, 0, 0);
    
    glColor3f(1, 0, 0);
    
    glScalef(5, 5, 5);
    
    drawsphere();
    
    
    
    glRotatef(ang/800, 0, 1, 1);
    
    glTranslatef(-500, 0, 0);
    
    glColor3f(.5, .5, .5);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    
    
  
    
    glPopMatrix();
    
    glRotatef(ang/800, 0, 1, 1);
    
    glTranslatef(500, 0, 0);
    
    glColor3f(.5, .5, .5);
    
    glScalef(3, 3, 3);
    
    drawsphere();
    

    
    glRotatef(ang/550, 0, 1, 1);
    
    glTranslatef(-200, 0, 0);
    
    //glRotatef(ang, 0, 1, 0);
    
    glScalef(5, 5, 5);
    
    
    glPopMatrix();
    
    
  
    
    glPopMatrix();
    
    glPopMatrix();
    

    
    /*---------------------------------------Draw Light Source-----------------------------------------*/
    glPushMatrix();
    glTranslated(light_pos2[0], light_pos2[1], light_pos2[2]);
    glColor3f(1, 1, 0);
    
    glPopMatrix();
	
	glutSwapBuffers();
    
    
	glutPostRedisplay();
    
    
    
    
}
Ejemplo n.º 6
0
void updateMovement(void) {
	if(deltaMove) computePos(deltaMove);
	if(deltaAngle) computeDir(deltaAngle);
}