Node<T> * NearestAncestor2(Node<T> *p1, Node<T> *p2) { std::stack<Node<T> *> s1; std::stack<Node<T> *> s2; Road(s1, p1); Road(s2, p2); int size = s1.size() - s2.size(); if (size > 0) { while (size--) s1.pop(); } else { while (size++) s2.pop(); } while (!s1.empty()) { if (s1.top() == s2.top()) return s1.top(); else { s1.pop(); s2.pop(); } } return NULL; }
void mainMenu() { u8 option=0; cpct_etm_setTileset2x4(g_tile_tileset_bg); cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_background); cpct_drawSprite (g_tile_titulo, getScreenPosition(5, 2), 32, 16); cpct_drawStringM0 ("PLAY GAME", getScreenPosition(5, 5), 15, 7); cpct_drawStringM0 ("CONTROLS", getScreenPosition(5, 7), 15, 7); cpct_drawStringM0 ("CREDITS", getScreenPosition(5, 9), 15, 7); initScroll(); initPlayer(); cpct_scanKeyboard_f (); do { waitNVSYNCs(3); cpct_akp_musicPlay(); Road(); drawPlayer(); if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) { --option; } else if ( cpct_isKeyPressed (Key_CursorDown) && option != 2) { ++option; } switch (option) { case 0: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 5), 4, 8); break; case 1: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 5), 4, 8); cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 9), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 7), 4, 8); break; case 2: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(3, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(3, 9), 4, 8); break; } cpct_scanKeyboard_f (); // waitNVSYNCs(5); } while (!cpct_isKeyPressed(Key_Return)); switch (option) { case 0: playMenu(); break; case 1: gameScene=CONTROLSSCREEN; break; case 2: gameScene=CREDITSSCEENE; break; } }
void playMenu() { u8 option=0; cpct_etm_setTileset2x4(g_tile_tileset_bg); cpct_etm_drawTilemap2x4_f(MAP_WIDTH_TILES, MAP_HEIGHT_TILES, SCR_VMEM, g_background); cpct_drawSprite (g_tile_titulo, getScreenPosition(5, 2), 32, 16); cpct_drawStringM0 ("PLAY GAME", getScreenPosition(5, 5), 15, 7); cpct_drawStringM0 ("INFINITY MODE", getScreenPosition(6, 7), 15, 7); cpct_drawStringM0 ("LEVELS MODE", getScreenPosition(6, 9), 15, 7); initScroll(); initPlayer(); cpct_scanKeyboard_f (); do { waitNVSYNCs(3); cpct_akp_musicPlay(); Road(); drawPlayer(); if ( cpct_isKeyPressed (Key_Esc)) { gameScene=MENUSCREEN; return; } else if ( cpct_isKeyPressed (Key_CursorUp) && option != 0) { --option; } else if ( cpct_isKeyPressed (Key_CursorDown) && option != 1) { ++option; } switch (option) { case 0: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 9), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(4, 7), 4, 8); break; case 1: cpct_drawSprite(g_tile_sky_blue, getScreenPosition(4, 7), 4, 8); cpct_drawSprite(sprite_skate, getScreenPosition(4, 9), 4, 8); break; } cpct_scanKeyboard_f (); // waitNVSYNCs(5); } while (!cpct_isKeyPressed(Key_Return)); switch (option) { case 0: cpct_akp_stop(); gameScene=PLAYGAMESCREEN; break; case 1: cpct_akp_stop(); gameScene=NEXTLEVELSCREEN; break; } }
/********************************************************** * * SUBROUTINE display() * * This is our main rendering subroutine, called each frame * *********************************************************/ void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); glWindowPos2i(width - 100, height - 15); if(enter && flag3) { SwitchGameplay(2); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer return; } Print("Score: %d", score); if(over) { SwitchGameplay(1); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer return; } // Erase the window and the depth buffer glClearColor(0,0.3,0.7,0); Background(3.5*dim); // draw space like looking texture gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f); glMatrixMode(GL_MODELVIEW); // Modeling transformation glLoadIdentity(); // Initialize the model matrix as identity // Perspective - set eye position gluLookAt(Ex,Ey,Ez , Ox,Oy,Oz , Ux,Uy,Uz); for ( i = 0; i < NUM_STAR; i++ ) { stars(star[i].x, star[i].y, star[i].z, star[i].a, star[i].b, star[i].c); } // draw laser cannon if fired if(bullet == 1 && space == 1) { laser_bullet(bx,by,bz,5,5,400); } // check if spaceship is hit by enemy if(px > ex-40 && px < ex+40 && py > ey-40 && py < ey+40 && pz > ez-40 && pz < ez+40 ) { space = 0; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; enemy = 0; } // Check if spaceship hits the wall if(px >= wall_x-100 && px <= wall_x+100 && py >= wall_y-30 && py <= wall_y+10 && pz >= wall_z-100 && pz <= wall_z+100 ) { space = 0; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; } // gravity, check if the spaceship fell off the road if( (px > 200 || px < -200) ) { py -= 5; if( py < -40) { space = 0; gravity = 1; CreateExplosion (); Mix_PlayMusic(blast,0); over = 1; } } if(space) spaceship(px, py, pz, -90+up, side, 180,0.85,0.85,0.85); if(enemy == 1) spaceship(ex, ey, ez, -90, 0, 0,1,1,1); glLoadIdentity(); glTranslatef(fx,fy,fz); if (fuel > 0) { glPushMatrix (); glBegin (GL_POINTS); for (i = 0; i < NUM_PARTICLES; i++) { glColor3fv (particles[i].color); glVertex3fv (particles[i].position); } glEnd (); for (i = 0; i < NUM_DEBRIS; i++) { glPushMatrix (); glTranslatef (debris[i].position[0], debris[i].position[1], debris[i].position[2]); glRotatef (debris[i].orientation[0], 1.0, 0.0, 0.0); glRotatef (debris[i].orientation[1], 0.0, 1.0, 0.0); glRotatef (debris[i].orientation[2], 0.0, 0.0, 1.0); glScalef (debris[i].scale[0], debris[i].scale[1], debris[i].scale[2]); glBegin (GL_TRIANGLES); glColor3f(((float) rand ()) / ((float) RAND_MAX), ((float) rand ()) / ((float) RAND_MAX), 0.3); glVertex3f (0.0, 0.5, 0.0); glVertex3f (-0.25, 0.0, 0.0); glVertex3f (0.25, 0.0, 0.0); glEnd (); glPopMatrix (); } } Road(road_x, road_y, road_z); wall(wall_x, wall_y, wall_z); glFlush(); // This force the execution of OpenGL commands glutSwapBuffers(); // In double buffered mode we invert the positions of the visible buffer and the writing buffer flag3++; }
void display() { glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */ if(view==0) { display1(); } else if (view==1) { display2(); } else if(view==2) { // Erase the window and the depth buffer glClearColor(0.6, 0.75, 0.85, 1); // sky color is light blue glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Enable Z-buffering in OpenGL glEnable(GL_DEPTH_TEST); glCullFace(GL_BACK); glLoadIdentity(); // Set the look at position for perspective projection gluLookAt( Ex, Ey, Ez, Ex + lx, Ey, Ez+lz, 0.0, 1, 0.0); glShadeModel(GL_SMOOTH); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); Sky(1000); glPopMatrix(); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); // Light switch if (light) { // Translate intensity to color vectors float Ambient[] = {0.01*ambient ,0.01*ambient ,0.01*ambient ,1.0}; float Diffuse[] = {0.01*diffuse ,0.01*diffuse ,0.01*diffuse ,1.0}; float Specular[] = {0.01*specular,0.01*specular,0.01*specular,1.0}; // Light position float Position[]={0,1000,5000}; // Draw light position as ball (still no lighting here) glColor3f(1,1,1); ball(Position[0],Position[1],Position[2] , 0.2); // OpenGL should normalize normal vectors glEnable(GL_NORMALIZE); // Enable lighting glEnable(GL_LIGHTING); // glColor sets ambient and diffuse color materials glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); // Enable light 0 glEnable(GL_LIGHT0); // Set ambient, diffuse, specular components and position of light 0 glLightfv(GL_LIGHT0,GL_AMBIENT ,Ambient); glLightfv(GL_LIGHT0,GL_DIFFUSE ,Diffuse); glLightfv(GL_LIGHT0,GL_SPECULAR,Specular); glLightfv(GL_LIGHT0,GL_POSITION,Position); } else glDisable(GL_LIGHTING); if(opt==1) { glPushMatrix(); glTranslatef( Ex + lx,0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car1); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } else if(opt==2) { glPushMatrix(); glTranslatef( Ex + lx, 0, Ez+lz-4); glRotatef(90, 1, 0, 0); glRotatef(180, 0, 1, 0); glColor3f(1,1,1); glCallList(car2); glPopMatrix(); int E=Ez+lz-4; if(E<=40) { Ex=0; Ez=1000; lx=0; lz=-1; } } cylinder(); Road(); for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(-50,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=40) { glPushMatrix(); glTranslated(170,10,i); glScaled(50,50,50); Tree(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(-70,-10,i); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=0; i<=1000; i+=60) { glPushMatrix(); glTranslated(70,-10,i); glRotated(90,0,1,0); glScaled(2,10,10); Lamp(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(-38,86.5,i+43); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=-60; i<=1000; i+=60) { glPushMatrix(); glTranslated(55,87,i+30); glScaled(5,5,5); lights(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(-50,-10,i); glScaled(10,10,10); trafficsignal(); glPopMatrix(); } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(0,0,i+40); zebracrossing(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(200,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-250,-15,i+30); glScaled(10,15,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(350,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(i=-60; i<=1000; i+=100) { glPushMatrix(); glTranslated(-400,-15,i+30); glScaled(10,30,10); buildings(); glPopMatrix(); } for(e=0; e<=1000; e+=155) { if(e%2==0) { glPushMatrix(); glTranslated(-16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } else { glPushMatrix(); glTranslated(16,-10,e); glScaled(6,6,6); roadpylon(); glPopMatrix(); } } for(i=0; i<=1000; i+=400) { glPushMatrix(); glTranslated(65,0,i); glScaled(10,10,10); roadsign(); glPopMatrix(); } xpos = xpos + xvel; if(xpos >= 30) { xvel = -xvel; } if( xpos <2) { xvel = -xvel; } glPushMatrix(); glTranslated(0,xpos,900); glRotated(-90,0,0,1); glRotated(-90,0,1,0); glScaled(2,2,2); glColor3f(1,1,1); glCallList(dragon); glPopMatrix(); glWindowPos2i(5,5); glColor3f(1,1,1); Print("Speed=%f",1,jump); } // Render the scene and make it visible ErrCheck("display"); glFlush(); glutSwapBuffers(); }