void gameInitial() { int i; initMap(map); drawInfo(global.score, global.life); pacman.mapX = 14; pacman.mapY = 18; pacman.screenX = 14 * UNIT + UNIT / 2 + OFFSET; pacman.screenY = 18 * UNIT + UNIT / 2 + OFFSET; pacman.dir = UP; pacman.speed = 1.2; drawPacman((int)pacman.screenX, (int)pacman.screenY, pacman.dir); for (i = 0; i < 3; i++) { ghost[i].mapX = 12 + i * 2; ghost[i].mapY = 16; ghost[i].screenX = mapToscreen(ghost[i].mapX) + UNIT / 2; ghost[i].screenY = mapToscreen(16); ghost[i].dir = UP; ghost[i].burst = 0; ghost[i].speed = 0.9; drawGhost(i, (int)ghost[i].screenX, (int)ghost[i].screenY, ghost[i].dir, ghost[i].burst); } ghost[3].mapX = 14; ghost[3].mapY = 12; ghost[3].screenX = mapToscreen(ghost[3].mapX); ghost[3].screenY = mapToscreen(12) + UNIT / 2; ghost[3].dir = LEFT; ghost[3].burst = 0; ghost[3].speed = 0.4; drawGhost(3, (int)ghost[3].screenX, (int)ghost[3].screenY, ghost[3].dir, ghost[3].burst); }
void render(){ display.Clear(); drawGhost(); drawBlock(CODE); drawMap(); drawBorders(); drawNextBlock(); sprintf(TEXT,"Score: %i",score); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (0)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Highscore: %i",hscore); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (1)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Next:"); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (4)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); }
void drawGameScene(sf::RenderWindow &window, const GameScene &scene) { drawField(window, scene.field); // Персонажи рисуются после поля. drawPackman(window, scene.packman); // pair имеет тип `const std::pair<const GhostId, Ghost> &` for (const auto &pair : scene.ghosts) { drawGhost(window, pair.second); } if ((scene.gameState == GameState::PlayerLosed) || (scene.gameState == GameState::PlayerWon)) { window.draw(scene.gameOverBackground); window.draw(scene.gameOverLabel); } }
void ghostRound() { int i; for (i = 0; i < 4; i++) { switch (ghost[i].dir) { case UP: if (map[ghost[i].mapY + 1][ghost[i].mapX] != 0) clearPerson(map, ghost[i].mapX, ghost[i].mapY + 1); clearPerson(map, ghost[i].mapX, ghost[i].mapY); handleGhostUp(i); break; case DOWN: if (map[ghost[i].mapY - 1][ghost[i].mapX] != 0) clearPerson(map, ghost[i].mapX, ghost[i].mapY - 1); clearPerson(map, ghost[i].mapX, ghost[i].mapY); handleGhostDown(i); break; case LEFT: if (map[ghost[i].mapY][ghost[i].mapX + 1] != 0) clearPerson(map, ghost[i].mapX + 1, ghost[i].mapY); clearPerson(map, ghost[i].mapX, ghost[i].mapY); handleGhostLeft(i); break; case RIGHT: if (map[ghost[i].mapY][ghost[i].mapX - 1] != 0) clearPerson(map, ghost[i].mapX - 1, ghost[i].mapY); clearPerson(map, ghost[i].mapX, ghost[i].mapY); handleGhostRight(i); break; } changeGhostDir(i); drawGhost(i, (int)ghost[i].screenX, (int)ghost[i].screenY, ghost[i].dir, ghost[i].burst); if (ghost[i].burst) { ghost[i].burst--; } } }
void animateMotion(int xtl, int ytl,int boardHeight,int boardWidth,Location *pacman,Location ghosts[],int height,int width, int lives,int state[],int score,int newScore[],int frightenLoop[],int loop){ /* This function is called after pacman is moved, and animates the movement of pacman, * and all the ghosts. While the ghosts' new positions are tabulated in moveGhosts, they * are not drawn until this function is called after pacman is moved */ int i,j,loops=2; int x=xtl+pacman->x*radius+radius/2; //first location to draw, will increment 5 times int y=ytl+pacman->y*radius+radius/2; Location delta; delta.x=(pacman->x-pacman->prevX)*radius/loops; delta.y=(pacman->y-pacman->prevY)*radius/loops; /* Currently, pacman only moves one space abruptly, he cannot smoothly move from cell to cell */ //for(j=1;j<=loops+1;j++){ //this loop allows the pacman movement to be smooth gfx_clear(); if(loop==1){i=3;} drawBoard(xtl,ytl,boardHeight,boardWidth,height,width,lives,i,score); drawPacman(x,y,pacman->orientation,0); //x+=delta.x; //y+=delta.y; //usleep(10000); //} for(i=blinky;i<=clyde;i++){ x=xtl+ghosts[i].x*radius+radius/2; y=ytl+ghosts[i].y*radius+radius/2; drawGhost(x,y,i,ghosts[i].orientation,state,frightenLoop[i]); } /* Check if there needs to be a score displayed */ if(newScore[0]){ gfx_color(120,120,120); gfx_text(xtl+newScore[1]*radius+radius/2,ytl+newScore[2]*radius+radius/2,num2str(newScore[0])); newScore[0]=0; newScore[1]=0; newScore[2]=0; } }
void pacMan() { DEBUGpln("in pacMan"); if(powerPillEaten>0){ for(int i =32+(powerPillEaten*17); i>-17; i--){ long nowish = millis(); cls(); drawPac(i,0,-1); if(powerPillEaten>0) drawScaredGhost(i-17,0); if(powerPillEaten>1) drawScaredGhost(i-34,0); if(powerPillEaten>2) drawScaredGhost(i-51,0); if(powerPillEaten>3) drawScaredGhost(i-68,0); matrix.swapBuffers(false); while(millis()-nowish<50) bgProcess(); //Give the background process some lovin' } powerPillEaten = 0; } else{ int hasEaten = 0; int powerPill = random(0,5); int numGhosts=random(0,4); if(powerPill ==0){ if(numGhosts==0) numGhosts++; powerPillEaten = numGhosts; } for(int i=-17; i<32+(numGhosts*17); i++){ cls(); long nowish = millis(); for(int j = 0; j<6;j++){ if( j*5> i){ if(powerPill==0 && j==4){ matrix.fillCircle(j*5,8,2,matrix.Color333(7,3,0)); } else{ matrix.fillRect(j*5,8,2,2,matrix.Color333(7,3,0)); } } } if(i==19 && powerPill == 0) hasEaten=1; drawPac(i,0,1); if(hasEaten == 0){ if(numGhosts>0) drawGhost(i-17,0,matrix.Color333(3,0,3)); if(numGhosts>1) drawGhost(i-34,0,matrix.Color333(3,0,0)); if(numGhosts>2) drawGhost(i-51,0,matrix.Color333(0,3,3)); if(numGhosts>3) drawGhost(i-68,0,matrix.Color333(7,3,0)); } else{ if(numGhosts>0) drawScaredGhost(i-17-(i-19)*2,0); if(numGhosts>1) drawScaredGhost(i-34-(i-19)*2,0); if(numGhosts>2) drawScaredGhost(i-51-(i-19)*2,0); if(numGhosts>3) drawScaredGhost(i-68-(i-19)*2,0); } matrix.swapBuffers(false); while(millis()-nowish<50) bgProcess(); //Give the background process some lovin' } } }
int main(int argc, char** argv) { osg::ArgumentParser arguments( &argc, argv ); std::string dbPath; arguments.read("--db_path", dbPath); std::srand ( unsigned ( std::time(0) ) ); auto board = Board(boardDefinition, boardSizeX, boardSizeY, dbPath); auto ghostFactory = GhostFactory(); auto main_obj = make_ref<osg::Group>(); main_obj->addChild(board.draw().get()); auto ghostModel = osgDB::readNodeFile(dbPath + "/cow.osg"); auto ghostCount = 16; while(ghostCount--) { main_obj->addChild(ghostFactory.drawGhost(board, ghostModel).get()); } // init rotate auto init_rotate = make_ref<osg::MatrixTransform>(); init_rotate->setMatrix( osg::Matrix::rotate(osg::PI * 2, osg::Vec3(1.0f, 0.0f, 0.0f)) ); // chain rotates init_rotate->addChild(main_obj); // Root group auto root = make_ref<osg::Group>(); root->addChild(init_rotate); // Setup fog if(FogEnabled) { osg::ref_ptr<osg::Fog> fog = new osg::Fog; fog->setMode( osg::Fog::EXP2 ); fog->setStart( 0.0f ); fog->setEnd(board.getFieldSizeX() * 20); fog->setDensity(0.0135); fog->setColor( osg::Vec4(0., 0., 0., 1.0) ); root->getOrCreateStateSet()->setAttributeAndModes(fog.get()); } // Start viewer osgViewer::Viewer viewer; // Set up flashlight auto lightSource = make_ref<osg::LightSource>(); lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF); auto light = lightSource->getLight(); const osg::Vec3 lightPosition{1.5, -1, -1}; // right, down, front light->setPosition(osg::Vec4{lightPosition, 1}); light->setDirection(osg::Vec3{0, 0, -1} * 30 - lightPosition); light->setSpotExponent(60); light->setSpotCutoff(90); light->setDiffuse(osg::Vec4(1, 1, 1, 1)); light->setAmbient(osg::Vec4(0.6, 0.6, 0.6, 1)); light->setSpecular(osg::Vec4(1, 1, 1, 1)); light->setLinearAttenuation(0.001); light->setConstantAttenuation(0.5); root->addChild(lightSource); double height = std::min(board.getFieldSizeX(), board.getFieldSizeY()) / 1.5; auto fpsManipulator = make_ref<FPSManipulator>(board, viewer, *light); fpsManipulator->setHomePosition( osg::Vec3d(board.getFieldCenterX(1), board.getFieldCenterY(10), height), osg::Vec3d(0.0f, 0.0f, height), osg::Vec3d(0.0f, 0.0f, 1.0f) ); auto keySwitch = make_ref<osgGA::KeySwitchMatrixManipulator>(); keySwitch->addNumberedMatrixManipulator(make_ref<osgGA::OrbitManipulator>()); keySwitch->addNumberedMatrixManipulator(fpsManipulator); viewer.setCameraManipulator(keySwitch); viewer.home(); viewer.setSceneData( root ); osgViewer::Viewer::Windows windows; viewer.getWindows(windows); viewer.getCamera()->setClearColor(osg::Vec4{0, 0, 0, 0}); viewer.getCamera()->getView()->setLightingMode(osg::View::HEADLIGHT); auto defaultLight = viewer.getCamera()->getView()->getLight(); defaultLight->setDiffuse(osg::Vec4(0, 0, 0, 1)); defaultLight->setAmbient(osg::Vec4(0, 0, 0, 1)); defaultLight->setSpecular(osg::Vec4(0, 0, 0, 1)); // Shaders auto program = make_ref<osg::Program>(); auto fragmentObject = make_ref<osg::Shader>(osg::Shader::FRAGMENT); loadShaderSource(fragmentObject, dbPath + "/shader.frag"); auto vertexObject = make_ref<osg::Shader>(osg::Shader::VERTEX); loadShaderSource(vertexObject, dbPath + "/shader.vert"); program->addShader(vertexObject); program->addShader(fragmentObject); root->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON); root->getOrCreateStateSet()->addUniform(new osg::Uniform("samplerName", TEXTURE_UNIT)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("Shininess", BoardObjectsShininess)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("FogEnabled", FogEnabled)); // Optimize osgUtil::Optimizer optimzer; optimzer.optimize(root); viewer.setUpViewOnSingleScreen(0); return viewer.run(); }
void drawDot(int i) { if (dots[i].isGhost) drawGhost(dots[i].rect.row, dots[i].rect.col); else drawRect4(dots[i].rect.col, dots[i].rect.row, dots[i].rect.width, dots[i].rect.height, WHITEINDEX); }
void titleScreen(int height,int width,Location ghosts[],Location *pacman,int state[]){ /*Draws the title screen */ int i=-1,x,y; gfx_clear(); gfx_color(255,255,255); gfx_text(width*.35+10,height*.8,"Programmed By: CORY JBARA"); gfx_text(width*.7,height*.8-32,"Use the arrow keys to move"); gfx_text(width*.7,height*.8,"Press any button to start"); /* Draw dots and point values */ gfx_color(255,200,0); gfx_fill_rectangle(width*.8-2,height/2-15,4,4); gfx_color(255,255,255); gfx_text(width*.8+10,height/2-9,"- 10 Points"); gfx_color(255,200,0); gfx_fill_circle(width*.8-4,height/2+15,8); gfx_color(255,255,255); gfx_text(width*.8+10,height/2+20,"- 50 Points"); /* Draws ghosts and their names */ x=width/3; y=height*.45+i*height/15; gfx_text(x,y,"CHARACTER ------------------------ NICKNAME"); for(i=0;i<4;i++){ state[i]=chase; x=width/4; y=height*.45+i*height/15; drawGhost(x,y,i,right,state,0); x=width/3; switch(i){ case blinky: gfx_color(255,0,0); gfx_text(x,y,"SHADOW -------------------------- \"BLINKY\""); break; case pinky: gfx_color(255,150,200); gfx_text(x,y,"SPEEDY -------------------------- \"PINKY\""); break; case inky: gfx_color(0,255,255); gfx_text(x,y,"BASHFUL -------------------------- \"INKY\""); break; case clyde: gfx_color(255,130,0); gfx_text(x,y,"POKEY -------------------------- \"CLYDE\""); break; } } /* Pacman being chased */ i++; y=height*.72; for(i=0;i<=3;i++){ x=width*.4+i*width/20; drawGhost(x,y,i,left,state,0); } drawPacman(width*.4-width/20,y,left,1); /* P */ gfx_color(255,255,0); gfx_fill_rectangle(10,height/5-50,width/15,150); gfx_fill_circle(10+width/15,height/5,50); gfx_color(0,0,0); gfx_fill_circle(10+width/15,height/5,10); /* A */ gfx_color(255,255,0); int loop=0; int x1=width*.1; int x2=width*.27; int center=(x1+x2)/2; y=height/5+100-1; while(x1<x2){//down gfx_line(x1,y,x2,y); if(loop%2){ x1++; x2--; } y--; loop++; } gfx_color(0,0,0); gfx_fill_circle(center,height*.24,10); /* C ::::: Code copied from drawPacman*/ int rad=200; x=width*.24+rad/2; y=height/5; gfx_color(255,255,0); gfx_fill_circle(x,y,rad/2-1); gfx_color(0,0,0); int r=rad/2-1; gfx_fill_triangle(x+r,y-r,x+r,y+r,right); /* M */ gfx_color(255,255,0); x=width*.47; y=height/5-50; gfx_fill_rectangle(x,y,width*.15,150); gfx_color(0,0,0); gfx_fill_triangle(x,y,x+width*.15,y,up); /* A */ gfx_color(255,255,0); loop=0; x1=width*.63; x2=width*.17 +x1; center=(x1+x2)/2; y=height/5+100-1; while(x1<x2){//down gfx_line(x1,y,x2,y); if(loop%2){ x1++; x2--; } y--; loop++; } gfx_color(0,0,0); gfx_fill_circle(center,height*.24,10); /* N */ gfx_color(255,255,0); x=width*.81; y=height/5-50; gfx_fill_rectangle(x,y,width*.15,150); gfx_color(0,0,0); x-=2; y-=height/10; gfx_fill_triangle(x+width*.1,y,x+width*.1,y+height*.2,right); }
int main() { memcpy(board2,board,sizeof(int)*rows*columns); int height=800,width=800; //height and width of screen gfx_open(width,height,"Pacman"); gfx_clear_color(0,0,0); gfx_clear(); int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board int xtopleft=width/2-boardWidth/2; //x coord of top left corner of board int ytopleft=height/2-boardHeight*9/16; //y coord of top left corner of board char movement; int i,lives=3;//start with 3 lives int win=0; int active=0; //this changes depending on number of dots left int initialDots=dotsNumber(); int remainingDots=dotsNumber(); int score=0; int loop[4]={0,0,0,0}; int frightenLoop[4]={0}; int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue Location pacman; Location ghosts[4];// enumerated to blinky, pinky, inky, clyde; /*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */ int state[4]={scatter,scatter,scatter,scatter}; while(1){ titleScreen(height,width,ghosts,&pacman,state); score=0; lives=3; win=0; for(i=0;i<=3;i++) loop[i]=0; //reset the game resetBoard(); gfx_wait(); /* This is the gameplay loop, will repeat every time a life is lost */ while(lives>0){ gfx_clear(); /* Initialize pacman's location */ pacman.x=pacman.prevX=7; pacman.y=pacman.prevY=12; pacman.orientation=right; /* Initialize ghost's locations */ for(i=blinky;i<=clyde;i++){state[i]=scatter;} ghosts[blinky].x=7; ghosts[blinky].prevX=8; ghosts[blinky].y=ghosts[blinky].prevY=6; ghosts[blinky].orientation=left; ghosts[pinky].x=7; ghosts[pinky].prevX=7; ghosts[pinky].y=7; ghosts[pinky].prevY=8; ghosts[pinky].orientation=up; ghosts[inky].x=ghosts[inky].prevX=6; ghosts[inky].y=7; ghosts[inky].prevY=8; ghosts[inky].orientation=right; ghosts[clyde].x=ghosts[clyde].prevX=8; ghosts[clyde].y=7; ghosts[clyde].prevY=8; ghosts[clyde].orientation=left; /* These two statements draw pacman and the board to begin the program */ drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score); drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0); for(i=blinky;i<=clyde;i++){ drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]); } /* This loop is the gameplay after all initialization */ while(1){ /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//} /* This block updates pacman position, checks for death * then updates ghosts' positions, then checks for death again */ movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } ghostState(loop,state,frightenLoop); active=activeGhosts(ghosts,loop); /* The next function animates the motion of all of the objects (pacman and ghosts */ animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]); /* The case to exit the loop is winning, when there are no dots left */ if(dotsNumber()==0){ //The player got all the dots, they won the game win=1; break; } } if(lives<=0){ gfx_clear(); printf("\n\nGAME OVER\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen else break;} else if(win){ printf("\n\nWINNER!\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game else break;} } } }
/* Function: instrDisplay * Parameters: none * Display function used when the player is at the instructions * screen. Prints a lot of text and rotating player models. Sets * up right click menu with "Play", "Title Screen" and "Quit" * options. Continuously redisplays. */ void instrDisplay() { static int angle = 0; int i; GLUquadricObj *sphere = gluNewQuadric(); /* Build Menu */ glutCreateMenu(menu); glutAddMenuEntry("Play!", 1); glutAddMenuEntry("Title Screen", 3); glutAddMenuEntry("Quit", 99); glutAttachMenu(GLUT_RIGHT_BUTTON); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); /* Position camera */ gluLookAt(camera[0], camera[1], camera[2], boardWidth / 2.0, boardWidth / 2.0, 1.0, 0.0, 1.0, 0.0); /* Turn off lighting, print text */ glColor3f(1.0, 1.0, 1.0); glDisable(GL_LIGHTING); displayText(9.0, 31.0, 0.0, "Instructions"); displayText(11.0, 27.5, 0.0, "PLAYERS"); displayText(2.0, 24.5, 0.0, "You:"); displayText(15.0, 24.5, 0.0, "The Enemy:"); displayText(11.0, 15.0, 0.0, "SCORING"); displayText(13.0, 13.0, 0.0, "10 pts"); displayText(13.0, 11.0, 0.0, "50 pts"); displayText(10.0, 8.5, 0.0, "1st: 200 pts"); displayText(10.0, 7.0, 0.0, "2nd: 400 pts"); displayText(10.0, 5.5, 0.0, "3rd: 800 pts"); displayText(10.0, 4.0, 0.0, "4th: 1600 pts"); displayText(4.0, 1.0, 0.0, "Extra player every 20000 pts"); displayText(6.0, -1.0, 0.0, "Use arrow keys to move"); glEnable(GL_LIGHTING); /* You: pacman */ glPushMatrix(); glTranslatef(7.0, 25.0, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); glScalef(2.0, 2.0, 2.0); drawPacman(); glPopMatrix(); /* Enemy: ghosts */ glPushMatrix(); glTranslatef(25.0, 24.5, 0.0); glScalef(2.0, 2.0, 2.0); for (i = 0; i < 4; i++) { glPushMatrix(); glRotatef(angle, 0.0, 1.0, 0.0); glRotatef(-90, 1.0, 0.0, 0.0); drawGhost(i); glPopMatrix(); glTranslatef(0.0, -1.0, 0.0); } glPopMatrix(); /* Scoring: small pellet */ glPushMatrix(); glTranslatef(11.0, 13.5, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); glColor3f((252.0 / 255.0), (182.0 / 255.0), (148.0 / 255.0)); gluSphere(sphere, 0.25, 10, 10); glPopMatrix(); /* Scoring: large pellet */ glPushMatrix(); glTranslatef(11.0, 11.5, 0.0); glRotatef(angle, 0.0, 1.0, 0.0); glColor3f((252.0 / 255.0), (182.0 / 255.0), (148.0 / 255.0)); gluSphere(sphere, 0.5, 10, 10); glPopMatrix(); /* Scoring: blue ghosts */ glPushMatrix(); glTranslatef(8.0, 8.0, 0.0); glScalef(2.0, 2.0, 2.0); glPushMatrix(); glRotatef(angle, 0.0, 1.0, 0.0); glRotatef(-90, 1.0, 0.0, 0.0); ghosts[0].colorf[0] = 0.0; ghosts[0].colorf[1] = 0.0; ghosts[0].colorf[2] = 1.0; drawGhost(0); glPopMatrix(); glTranslatef(0.0, -1.0, 0.0); colorGhosts(); glPopMatrix(); angle = (angle + 2) % 360; /* rotation angle */ gluDeleteQuadric(sphere); glFlush(); glutSwapBuffers(); glutPostRedisplay(); }
/* Function: gameDisplay * Parameters: none * Display function used when the player is playing the game. * Draws score, top score, the board, pacman and ghosts. Sets * up right click menu with "Pause", "Toggle Tilt", "End Game" * and "Quit" options. If the gameStarted flag is set, re-registers * timer functions for movement. */ void gameDisplay() { int x, y, i; int digits = 1; char scoreStr[6]; GLUquadricObj *sphere = gluNewQuadric(); /* Build Menu */ glutCreateMenu(menu); if (gameStarted) glutAddMenuEntry("Pause", 5); else glutAddMenuEntry("Un-pause", 5); glutAddMenuEntry("Toggle Tilt", 10); glutAddMenuEntry("End Game", 3); glutAddMenuEntry("Quit", 99); glutAttachMenu(GLUT_RIGHT_BUTTON); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); /* Position camera */ gluLookAt(camera[0], camera[1], camera[2], boardWidth / 2.0, boardWidth / 2.0, 1.0, 0.0, 1.0, 0.0); /* Translate center of board to origin for rotation */ glTranslatef(boardWidth / 2.0, boardHeight / 2.0, 0.0); glRotatef(theta[0], 1.0, 0.0, 0.0); glRotatef(theta[1], 0.0, 1.0, 0.0); glRotatef(theta[2], 0.0, 0.0, 1.0); glTranslatef(-(boardWidth / 2.0), -(boardHeight / 2.0), 0.0); /* Draw the floor */ glBegin(GL_QUADS); glColor3f(0.5, 0.2, 0.2); glVertex2f(0.0, 0.0); glVertex2f(boardWidth, 0.0); glVertex2f(boardWidth, boardHeight); glVertex2f(0.0, boardHeight); glEnd(); /* Draw the walls */ glCallList(walls); /* Draw everything else */ for (y = 0; y < boardHeight; y++) { for (x = 0; x < boardWidth; x++) { /* Pellet */ if (board[y][x] == '.') { glDisable(GL_LIGHTING); glBegin(GL_POINTS); glColor3f((252.0 / 255.0), (182.0 / 255.0), (148.0 / 255.0)); glVertex3f((GLfloat)x + 0.5, boardHeight - (GLfloat)y - 0.5, 0.5); glEnd(); glEnable(GL_LIGHTING); } /* Super-pellet */ if (board[y][x] == 'P') { glTranslatef(x + 0.5, ((boardHeight - y) - 0.5), 0.5); glColor3f((252.0 / 255.0), (182.0 / 255.0), (148.0 / 255.0)); gluSphere(sphere, 0.3, 12, 12); glTranslatef(-(x + 0.5), -((boardHeight - y) - 0.5), -0.5); } /* Ghost door */ if (board[y][x] == 'G') { glBegin(GL_QUADS); glColor3f((252.0 / 255.0), (182.0 / 255.0), (220.0 / 255.0)); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y - 0.5, 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y - 0.5, 0.0); glVertex3f((GLfloat)x + 1.0, boardHeight - (GLfloat)y - 0.5, wallHeight); glVertex3f((GLfloat)x, boardHeight - (GLfloat)y - 0.5, wallHeight); glEnd(); } } } /* Draw pacman */ glPushMatrix(); glTranslatef(pacman.x + (pacman.size / 2.0), pacman.y - (pacman.size / 2.0), (pacman.size / 2.0)); drawPacman(); glPopMatrix(); /* Draw the ghosts */ for (i = 0; i < 4; i++) { glPushMatrix(); glTranslatef(ghosts[i].x + (ghosts[i].size / 2.0), ghosts[i].y - (ghosts[i].size / 2.0), 0.0); drawGhost(i); glPopMatrix(); } /* Draw players left */ glPushMatrix(); glTranslatef(boardWidth - 1.0, boardHeight + 2.0, 0.5); for (i = 0; i < playersLeft; i++) { glColor3fv(pacman.colorf); gluSphere(sphere, (pacman.size / 2.0) - 0.1, 10, 10); glTranslatef(-1.0, 0.0, 0.0); } glPopMatrix(); /* Flash points if Pacman ate a ghost */ if (flashPoints) { glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); displayText((GLfloat)flashPointsX, (GLfloat)flashPointsY, 2.5, itoa(flashPointsScore, scoreStr, 10)); glEnable(GL_LIGHTING); } /* Flash READY! if just starting */ if (flashReady > 0) { if (flashReady == 1 || flashReady == 3 || flashReady == 5) { glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); displayText(((GLfloat)boardWidth / 2.0) - 2.0, (GLfloat)boardHeight / 2.0, 2.0, "READY!"); glEnable(GL_LIGHTING); } } /* Print score */ glDisable(GL_LIGHTING); glColor3f(1.0, 1.0, 1.0); displayText(0.5, (GLfloat)boardHeight + 3.0, 1.0, "SCORE"); displayText(0.5, (GLfloat)boardHeight + 1.5, 1.0, itoa(score, scoreStr,10)); displayText(10.0, (GLfloat)boardHeight + 3.0, 1.0, "TOP SCORE"); displayText(11.0, (GLfloat)boardHeight + 1.5, 1.0, itoa(topScore, scoreStr, 10)); glEnable(GL_LIGHTING); gluDeleteQuadric(sphere); glFlush(); glutSwapBuffers(); }
void draw::gameDraw(const modify *level, sf::RenderWindow &mainWindow){ drawMap(mainWindow, level->loadedMap, false); drawPac(mainWindow, level->pacX, level->pacY, level->pacDirection, level->switchPac, level->pacOpen); drawGhost(mainWindow, level->ghostX, level->ghostY, level); }