예제 #1
0
파일: PacMan.cpp 프로젝트: amw/pacman3d
void PacMan::initializeGL( QGLWidget & target ) {
  QImage pacman( "textures/pacman.png" );
  this->pacmanTexture = target.bindTexture( pacman );

  this->sphereList = glGenLists( 1 );
  this->sphereQuadric = gluNewQuadric();
  gluQuadricTexture( this->sphereQuadric, true );

  glNewList( this->sphereList, GL_COMPILE );
  {
    glBindTexture( GL_TEXTURE_2D, this->pacmanTexture );
    this->material.updateGlState( Material::Front );
    glRotatef( 180, 1.0f, 0.0f, 0.0f );
    gluSphere( this->sphereQuadric, this->radius, 360 / 5, 180 / 5 );
  }
  glEndList();
}
예제 #2
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	try
	{

		CL_OpenGLWindowDescription desc;

		desc.set_title("ClanLib AnimCursor Test");
		desc.set_size(CL_Size(800, 600), true);
		CL_DisplayWindow window(desc);

		// Connect the Window close event
		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

		// Connect a keyboard handler to on_key_up()
		CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

		// Get the graphic context
		CL_GraphicContext gc = window.get_gc();

		CL_Font font = CL_Font(gc, "Tahoma", 20);

		CL_PixelBuffer pacman("pacman.png");

		CL_SpriteDescription description;
		CL_Size size(22, 22);

		for (int frame_cnt=0; frame_cnt < 6; frame_cnt++)
		{
			CL_PixelBuffer frame(size.width, size.height, cl_rgba8);
			pacman.convert(frame, size, CL_Rect((frame_cnt * 28) + 4, 4, size));
			description.add_frame(frame);
			description.set_frame_delay(frame_cnt, 0.1);
		}

		CL_Point hotspot(0,0);
		CL_Cursor cursor(window, description, hotspot);
		window.set_cursor(cursor);

		// Run until someone presses escape
		while (!quit)
		{
			gc.clear(CL_Colorf(0.0f,0.0f,0.5f));

			font.draw_text(gc, 32, 32, "Observe the animated cursor");

			// Flip the display, showing on the screen what we have drawed
			// since last call to flip()
			window.flip(1);

			// This call processes user input and other events
			CL_KeepAlive::process();
		}
	}
	catch(CL_Exception& exception)
	{
		// Create a console window for text-output if not available
		CL_ConsoleWindow console("Console", 80, 200);

		CL_Console::write_line("Exception caught:");
		CL_Console::write_line(exception.message);

		// Display the stack trace (if available)
		std::vector<CL_String> stacktrace = exception.get_stack_trace();
		int size = stacktrace.size();
		if (size > 0)
		{
			CL_Console::write_line("Stack Trace:");
			for (int cnt=0; cnt < size; cnt++)
			{
				CL_Console::write_line(stacktrace[cnt]);
			}
		}

		console.display_close_message();

		return -1;
	}
	return 0;
}
예제 #3
0
//
// Fix a compile error - see http://stackoverflow.com/questions/920500/what-is-the-purpose-of-cxa-pure-virtual for details.
//
// extern "C" void __cxa_pure_virtual() { while (1); }
//
// The main entry point
//
int main(void) {
	//
	// Board and port initialisations
	//
	StellarisLaunchpad pad;
	StellarisPort port1(SYSCTL_PERIPH_GPIOD);
	StellarisPort port2(SYSCTL_PERIPH_GPIOE);
	//
	// Create a set of objects representing the output pins
	//
	StellarisPortPin clock(GPIO_PORTD_BASE, GPIO_PIN_1);
	StellarisPortPin shift(GPIO_PORTD_BASE, GPIO_PIN_2);
	StellarisPortPin chipSelect(GPIO_PORTD_BASE, GPIO_PIN_3);
	StellarisPortPin a(GPIO_PORTE_BASE, GPIO_PIN_1);
	StellarisPortPin b(GPIO_PORTE_BASE, GPIO_PIN_2);
	StellarisPortPin c(GPIO_PORTE_BASE, GPIO_PIN_3);

	//
	// Create and initialise the LedArrayDriver
	//
	LedArrayDriver led(&clock, &chipSelect, &shift, &a,&b,&c, NBR_OF_DISPLAY_ROWS, NBR_OF_DISPLAY_COLUMNS);
	led.init();

	AsciiMessage welcome("**** Welcome to the Museum of Computing - open Fridays 10am to 4pm and Saturdays 9:30am to 5pm ****");
	AsciiMessage exhib1("**** Visit our \"Gaming on the Go\" exhibition - 35 years of handheld games consoles ****");
	AsciiMessage retroGaming("**** Join our computer games sessions on Saturdays for some retro gaming ****");
	AsciiMessage website("**** See us on the web at http://www.museum-of-computing.org.uk/ ****");
	AsciiMessage hackspace("**** Join the Swindon Hackspace at the Museum of Computing - Wednesdays 6:30pm to 10pm ****");
	AsciiMessage compClub("**** Ask about our Kids Computer Club on Saturdays ****");
	AsciiMessage schoolVisit("**** Arrange a school visit and take part in a tour of the museum, quizzes and mini projects ****");
	AsciiMessage shop("**** Our shop has a range of gifts and souvenirs ****");

	RepeatedGraphic multiInvader(invader, 10, 8);
	AnimatedGraphic pacman(animPacman, 17, 7);// columns * frames
	AnimatedGraphic invader(animInvader, 11, 4);// columns * frames


	LeftScroller scrollLeft1(led, invader, 2, displayBuffer);
	LeftScroller scrollLeft2(led, welcome, 1, displayBuffer);
	LeftScroller scrollLeft3(led, exhib1, 1, displayBuffer);
	LeftScroller scrollLeft4(led, multiInvader, 1, displayBuffer);
	LeftScroller scrollLeft5(led, retroGaming, 1, displayBuffer);
	LeftScroller scrollLeft6(led, pacman, 1, displayBuffer);
	LeftScroller scrollLeft7(led, compClub, 1, displayBuffer);
	LeftScroller scrollLeft8(led, schoolVisit, 1, displayBuffer);
	LeftScroller scrollLeft9(led, website, 1, displayBuffer);
	LeftScroller scrollLeft10(led, shop, 1, displayBuffer);
	LeftScroller scrollLeft11(led, hackspace, 1, displayBuffer);
	do
	{
		scrollLeft1.init();  while(scrollLeft1.animate());
		scrollLeft2.init();  while(scrollLeft2.animate());
		scrollLeft3.init();  while(scrollLeft3.animate());
		scrollLeft4.init();  while(scrollLeft4.animate());
		scrollLeft5.init();  while(scrollLeft5.animate());
		scrollLeft6.init();  while(scrollLeft6.animate());
		scrollLeft7.init();  while(scrollLeft7.animate());
		scrollLeft8.init();  while(scrollLeft8.animate());
		scrollLeft9.init();  while(scrollLeft9.animate());
		scrollLeft10.init(); while(scrollLeft10.animate());
		scrollLeft11.init(); while(scrollLeft11.animate());
	} while(1);
}
예제 #4
0
파일: main.cpp 프로젝트: SamReha/pacman
int main(int, char const**)
{
  // Create the main window
  sf::RenderWindow window(sf::VideoMode(TILE_WIDTH*28, TILE_WIDTH*31), "PAC MAN");
  window.setFramerateLimit(FRAME_RATE);
  
  // Set the Icon
  sf::Image icon;
  if (!icon.loadFromFile(resourcePath() + "icon.png")) {
    return EXIT_FAILURE;
  }
  window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
  
  // Try to open the given texture
  sf::Texture tileset_texture;
  if (!tileset_texture.loadFromFile(resourcePath() + "data/full_texture_x3.png")) {
    return EXIT_FAILURE;
  }
  
  // More importantly, let's generate our tileset from that texture.
  AssetManager assetManager(TILE_WIDTH);
  std::map<sf::String, sf::Sprite> spriteSet = assetManager.generateSpriteSet(&tileset_texture);
  std::map<sf::String, PacTile*> tileSet;

  PacTile outer_top_left_corner(spriteSet["outer_top_left_corner"], "WALL");
  tileSet["outer_top_left_corner"] = &outer_top_left_corner;
  
  PacTile weird_north_left_corner(spriteSet["weird_north_left_corner"], "WALL");
  tileSet["weird_north_left_corner"] = &weird_north_left_corner;
  
  PacTile weird_west_upper_corner(spriteSet["weird_west_upper_corner"], "WALL");
  tileSet["weird_west_upper_corner"] = &weird_west_upper_corner;
  
  PacTile weird_east_upper_corner(spriteSet["weird_east_upper_corner"], "WALL");
  tileSet["weird_east_upper_corner"] = &weird_east_upper_corner;
  
  PacTile weird_west_lower_corner(spriteSet["weird_west_lower_corner"], "WALL");
  tileSet["weird_west_lower_corner"] = &weird_west_lower_corner;
  
  PacTile weird_east_lower_corner(spriteSet["weird_east_lower_corner"], "WALL");
  tileSet["weird_east_lower_corner"] = &weird_east_lower_corner;
  
  PacTile box_top_left_corner(spriteSet["box_top_left_corner"], "WALL");
  tileSet["box_top_left_corner"] = &box_top_left_corner;
  
  PacTile top_right_corner(spriteSet["top_right_corner"], "WALL");
  tileSet["top_right_corner"] = &top_right_corner;
  
  PacTile weird_north_right_corner(spriteSet["weird_north_right_corner"], "WALL");
  tileSet["weird_north_right_corner"] = &weird_north_right_corner;
  
  PacTile box_top_right_corner(spriteSet["box_top_right_corner"], "WALL");
  tileSet["box_top_right_corner"] = &box_top_right_corner;
  
  PacTile bottom_right_corner(spriteSet["bottom_right_corner"], "WALL");
  tileSet["bottom_right_corner"] = &bottom_right_corner;
  
  PacTile box_bottom_right_corner(spriteSet["box_bottom_right_corner"], "WALL");
  tileSet["box_bottom_right_corner"] = &box_bottom_right_corner;
  
  PacTile bottom_left_corner(spriteSet["bottom_left_corner"], "WALL");
  tileSet["bottom_left_corner"] = &bottom_left_corner;
  
  PacTile box_bottom_left_corner(spriteSet["box_bottom_left_corner"], "WALL");
  tileSet["box_bottom_left_corner"] = &box_bottom_left_corner;
  
  PacTile top_edge(spriteSet["top_edge"], "WALL");
  tileSet["top_edge"] = &top_edge;
  
  PacTile box_top_edge(spriteSet["box_top_edge"], "WALL");
  tileSet["box_top_edge"] = &box_top_edge;
  
  PacTile left_edge(spriteSet["left_edge"], "WALL");
  tileSet["left_edge"] = &left_edge;
  
  PacTile inner_left_edge(spriteSet["inner_left_edge"], "WALL");
  tileSet["inner_left_edge"] = &inner_left_edge;
  
  PacTile right_edge(spriteSet["right_edge"], "WALL");
  tileSet["right_edge"] = &right_edge;
  
  PacTile inner_right_edge(spriteSet["inner_right_edge"], "WALL");
  tileSet["inner_right_edge"] = &inner_right_edge;
  
  PacTile bottom_edge(spriteSet["bottom_edge"], "WALL");
  tileSet["bottom_edge"] = &bottom_edge;
  
  PacTile box_bottom_edge(spriteSet["box_bottom_edge"], "WALL");
  tileSet["box_bottom_edge"] = &box_bottom_edge;
  
  // House tiles!
  PacTile house_top_right_corner(spriteSet["house_top_right_corner"], "WALL");
  tileSet["house_top_right_corner"] = &house_top_right_corner;
  
  PacTile house_bottom_right_corner(spriteSet["house_bottom_right_corner"], "WALL");
  tileSet["house_bottom_right_corner"] = &house_bottom_right_corner;
  
  PacTile house_top_left_corner(spriteSet["house_top_left_corner"], "WALL");
  tileSet["house_top_left_corner"] = &house_top_left_corner;
  
  PacTile house_bottom_left_corner(spriteSet["house_bottom_left_corner"], "WALL");
  tileSet["house_bottom_left_corner"] = &house_bottom_left_corner;
  
  PacTile door(spriteSet["door"], "WALL");
  tileSet["door"] = &door;
  
  PacTile floor(spriteSet["floor"], "FLOOR");
  tileSet["floor"] = &floor;
  
  // Load up the map!
  Map map(sf::Vector2<double>(0, 0), sf::Vector2<int>(28, 31), TILE_WIDTH);
  map.configureMap(tileSet);
  
  // Create a graphical text to display
  /*sf::Font font;
  if (!font.loadFromFile(resourcePath() + "sansation.ttf")) {
    return EXIT_FAILURE;
  }

  // Load a music to play
  sf::Music music;
  if (!music.openFromFile(resourcePath() + "nice_music.ogg")) {
    return EXIT_FAILURE;
  }*/
  
  // Declare the ghosts!
  Pinky pinky(sf::Vector2<double>(0, 0), "HOME");
  Blinky blinky(sf::Vector2<double>(0, 0), "HOME");
  Inky inky(sf::Vector2<double>(0, 0), "HOME");
  Sue sue(sf::Vector2<double>(0, 0), "HOME");
  
  // Game variables
  // Assemble the PacMan!
  PacMan pacman(1, 1, 1, 60, map);
  std::vector<sf::Sprite> pacUpSprites;
  std::vector<sf::Sprite> pacDownSprites;
  std::vector<sf::Sprite> pacLeftSprites;
  std::vector<sf::Sprite> pacRightSprites;
  
  pacUpSprites.push_back(spriteSet["pacUp0"]);
  pacUpSprites.push_back(spriteSet["pacUp1"]);
  pacUpSprites.push_back(spriteSet["pacUp2"]);
  pacUpSprites.push_back(spriteSet["pacUp1"]);
  
  pacDownSprites.push_back(spriteSet["pacDown0"]);
  pacDownSprites.push_back(spriteSet["pacDown1"]);
  pacDownSprites.push_back(spriteSet["pacDown2"]);
  pacDownSprites.push_back(spriteSet["pacDown1"]);
  
  pacLeftSprites.push_back(spriteSet["pacLeft0"]);
  pacLeftSprites.push_back(spriteSet["pacLeft1"]);
  pacLeftSprites.push_back(spriteSet["pacLeft2"]);
  pacLeftSprites.push_back(spriteSet["pacLeft1"]);
  
  pacRightSprites.push_back(spriteSet["pacRight0"]);
  pacRightSprites.push_back(spriteSet["pacRight1"]);
  pacRightSprites.push_back(spriteSet["pacRight2"]);
  pacRightSprites.push_back(spriteSet["pacRight1"]);
  
  pacman.setUpSprites(pacUpSprites, 4);
  pacman.setDownSprites(pacDownSprites, 4);
  pacman.setLeftSprites(pacLeftSprites, 4);
  pacman.setRightSprites(pacRightSprites, 4);
  pacman.setVelocity(sf::Vector2<double>(0.0, 1.0));
  pacman.initialize("RIGHT");
  
  
  // Play the music
  // music.play();
  
  // Start the game loop
  while (window.isOpen()) {
    // Process events
    sf::Event event;
    while (window.pollEvent(event)) {
      // Close window: exit
      if (event.type == sf::Event::Closed) {
        window.close();
      }

      // Escape pressed: exit
      if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
        window.close();
      }
    }
    
    pacman.update(map);

    // DRAWING THE SCREEN
    window.clear();
    
    // Draw the map
    drawMap(&window, map);
    
    // Then, draw any pellets / fruits, those type things
    
    // Then, draw the ghosts
    
    // Then, draw pacman
    window.draw(pacman.getSprite());
    
    // Update the window
    window.display();
  }

  return EXIT_SUCCESS;
}
예제 #5
0
int main(){


	pillPosition = newPillPosition();
	fantasma A(41, 14, 2);
	fantasma B(43, 14, 3);
	fantasma C(40, 14, 4);
	fantasma D(39, 14, 5);
	pintar_mapa();

	while (vidas > 0 && puntos < 1950){
		marcador();
		borrar_pacman(x, y);
		anteriorpx = x; anteriorpy = y;


		teclear();

		if (dir == 0 && mapa[y - 1][x] != 'X' && mapa[y - 1][x] != 'A' && mapa[y - 1][x] != 'Y' &&
			mapa[y - 1][x] != 'B' && mapa[y - 1][x] != 'C' && mapa[y - 1][x] != 'D')                       y--;


		else if (dir == 1 && mapa[y + 1][x] != 'X' && mapa[y + 1][x] != 'A' && mapa[y + 1][x] != 'Y' &&
			mapa[y + 1][x] != 'B' && mapa[y + 1][x] != 'C' && mapa[y + 1][x] != 'D')                       y++;


		pacman(x, y);
		Sleep(55);
		borrar_pacman(x, y);

		B.choque_pacman();
		C.choque_pacman();
		D.choque_pacman();
		A.choque_pacman();

		//A.mover_fantasma();
		anteriorpx = x; anteriorpy = y;
		teclear();


		if (dir == 2 && mapa[y][x + 1] != 'X' && mapa[y][x + 1] != 'A' && mapa[y][x + 1] != 'Y' &&
			mapa[y][x + 1] != 'B' && mapa[y][x + 1] != 'C' && mapa[y][x + 1] != 'D')                       x++;


		else if (dir == 3 && mapa[y][x - 1] != 'X' && mapa[y][x - 1] != 'A' && mapa[y][x - 1] != 'Y' &&
			mapa[y][x - 1] != 'B' && mapa[y][x - 1] != 'C' && mapa[y][x - 1] != 'D')                         x--;

		A.mover_fantasma();
		B.mover_fantasma();
		C.mover_fantasma();
		D.mover_fantasma();
		pacman(x, y);
		choquePildora();
		if (pillTimer < 0){
			pill(pillPosition);
		}
		else{
				pillTimer--;
		}
		Sleep(55);

		//pacman(x,y);
		//rutina atajo
		if (x < 17) {
			borrar_pacman(x, y);
			x = 61;
		}
		else if (x > 62){
			borrar_pacman(x, y);
			x = 18;
		}



	}



	for (int i = 0; i <= vidas; i++){
		gotoxy(5, i + 27); printf(" ");

	}

	system("pause>NULL");
	return 0;

}
예제 #6
0
파일: pacman.c 프로젝트: denzelr/Pacman
/*
 *  OpenGL (GLUT) calls this routine to display the scene
 */
void display()
{
   //  Erase the window and the depth buffer
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   //  Enable Z-buffering in OpenGL
   glEnable(GL_DEPTH_TEST);
   //  Undo previous transformations
   glLoadIdentity();
   //  Orthogonal - set world orientation
   //glTranslated(pos[0],0,pos[1]);
   glRotatef(ph,1,0,0);
   glRotatef(th,0,1,0);
    
    //  Flat or smooth shading
    glShadeModel(smooth ? GL_SMOOTH : GL_FLAT);
    
    // Add light to the scene
    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[]  = {distance*Cos(zh),ylight,distance*Sin(zh),1.0};
        //  Draw light position as ball (still no lighting here)
        glColor3f(1,1,1);
        lightSource(Position[0],Position[1],Position[2] , 0.1);
        //  OpenGL should normalize normal vectors
        glEnable(GL_NORMALIZE);
        //  Enable lighting
        glEnable(GL_LIGHTING);
        //  Location of viewer for specular calculations
        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,local);
        //  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);
    // Draw Bell towers
    bell(8,2,-6,.25);
    bell(-8,2,-6,.25);
    
    for (int i = -9; i <= 9; i+=2){
        for (int j = -5; j <= 5; j +=4){
            floorTiles(i,-.5,j,1.2,0);
        }
    }
    for (int i = -8; i <= 8; i+=2){
        for (int j = -3; j <= 5; j +=4){
            floorTiles(i,-.5,j,1.2,.5);
        }
    }
   
    
   // Draw Game grid
     for (int k = -4; k <= -1; k++){
        cube(k,0,-4, .5,.5,.5 , 0);
        cube(k,0,4, .5,.5,.5 , 0);
        cube(-4,0,k, .5,.5,.5 , 0);
        cube(4,0,k, .5,.5,.5 , 0);
    }
    for (int k = 1; k <= 4; k++){
        cube(k,0,-4, .5,.5,.5 , 0);
        cube(k,0,4, .5,.5,.5 , 0);
        cube(-4,0,k, .5,.5,.5 , 0);
        cube(4,0,k, .5,.5,.5 , 0);
    }
    for (int k = -10; k <= 10; k++){
        cube(k,0,-6, .5,.5,.5 , 0);
        cube(k,0,6, .5,.5,.5 , 0);
    }
    for (int k = -6; k <= 6; k++){
        cube(-10,0,k, .5,.5,.5 , 0);
        cube(10,0,k, .5,.5,.5 , 0);
    }
    for (int k = -4; k <= 4; k++){
        cube(-8,0,k, .5,.5,.5 , 0);
        cube(8,0,k, .5,.5,.5 , 0);
    }
    for (int k = -6; k <= -5; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int k = -3; k <= 3; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int k = 5; k <= 6; k++){
        cube(-6,0,k, .5,.5,.5 , 0);
        cube(6,0,k, .5,.5,.5 , 0);
    }
    for (int j = -2; j <= -1; j++){
        cube(j,0,-2, .5,.5,.5 , 0);
        cube(j,0,2, .5,.5,.5 , 0);
        cube(-2,0,j, .5,.5,.5 , 0);
        cube(2,0,j, .5,.5,.5 , 0);
    }
    for (int l = 1; l <= 2; l++){
        cube(l,0,-2, .5,.5,.5 , 0);
        cube(l,0,2, .5,.5,.5 , 0);
        cube(-2,0,l, .5,.5,.5 , 0);
        cube(2,0,l, .5,.5,.5 , 0);
    }
    for (int i = -6; i <= 6; i++){
        for (int j = -10; j <= 10; j++){
            if (balls[i+6][j+10] == 1){
                ball(j,0,i, 0.1,4);
            }
        }
    }
    
   // Draw ghosts and animate movement
    //Red Ghost Movement
    if (redTrack == 0){
        posx1 += dx;
        ghost(posx1,0,-5 , 0.4, 0, 0);
        if (posx1 >= -7){
            redTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 1){
        posz1 += dx;
        ghost(-7,0,posz1 , 0.4, 0, 0);
        if (posz1 >= 5){
            redTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 2){
        posx1 -= dx;
        ghost(posx1,0,5 , 0.4, 0, 0);
        if (posx1 <= -9){
            redTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (redTrack == 3){
        posz1 -= dx;
        ghost(-9,0,posz1 , 0.4, 0, 0);
        if (posz1 <= -5){
            redTrack = 0;
        }
        glutIdleFunc(idle);
    }
   
    //Blue Ghost Movement
    if (blueTrack == 0){
        posx2 += dx;
        ghost(posx2,0,-5 , 0.4, 0, 1);
        if (posx2 >= 5){
            blueTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 1){
        posz2 += dx;
        ghost(5,0,posz2 , 0.4, 0, 1);
        if (posz2 >= 5){
            blueTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 2){
        posx2 -= dx;
        ghost(posx2,0,5 , 0.4, 0, 1);
        if (posx2 <= -5){
            blueTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (blueTrack == 3){
        posz2 -= dx;
        ghost(-5,0,posz2 , 0.4, 0, 1);
        if (posz2 <= -5){
            blueTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    //Pink Ghost Movement
    if (pinkTrack == 0){
        posx3 += dx;
        ghost(posx3,0,-5 , 0.4, 0, 2);
        if (posx3 >= 9){
            pinkTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 1){
        posz3 += dx;
        ghost(9,0,posz3 , 0.4, 0, 2);
        if (posz3 >= 5){
            pinkTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 2){
        posx3 -= dx;
        ghost(posx3,0,5 , 0.4, 0, 2);
        if (posx3 <= 7){
            pinkTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (pinkTrack == 3){
        posz3 -= dx;
        ghost(7,0,posz3 , 0.4, 0, 2);
        if (posz1 <= -5){
            pinkTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    //Orange Ghost Movement
    if (orangeTrack == 0){
        posx4 += dx;
        ghost(posx4,0,-3 , 0.4, 0, 3);
        if (posx4 >= 3){
            orangeTrack = 1;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 1){
        posz4 += dx;
        ghost(3,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 0){
            orangeTrack = 2;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 2){
        posx4 += dx;
        ghost(posx4,0,0 , 0.4, 0, 3);
        if (posx4 >= 5){
            orangeTrack = 3;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 3){
        posz4 -= dx;
        ghost(5,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -4){
            orangeTrack = 4;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 4){
        posx4 += dx;
        ghost(posx4,0,-4 , 0.4, 0, 3);
        if (posx4 >= 7){
            orangeTrack = 5;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 5){
        posz4 += dx;
        ghost(7,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 4){
            orangeTrack = 6;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 6){
        posx4 -= dx;
        ghost(posx4,0,4 , 0.4, 0, 3);
        if (posx4 <= 5){
            orangeTrack = 7;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 7){
        posz4 += dx;
        ghost(5,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 5){
            orangeTrack = 8;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 8){
        posx4 -= dx;
        ghost(posx4,0,5 , 0.4, 0, 3);
        if (posx4 <= -5){
            orangeTrack = 9;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 9){
        posz4 -= dx;
        ghost(-5,0,posz4 , 0.4, 0, 3);
        if (posz4 <= 4){
            orangeTrack = 10;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 10){
        posx4 -= dx;
        ghost(posx4,0,4 , 0.4, 0, 3);
        if (posx4 <= -7){
            orangeTrack = 11;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 11){
        posz4 -= dx;
        ghost(-7,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -4){
            orangeTrack = 12;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 12){
        posx4 += dx;
        ghost(posx4,0,-4 , 0.4, 0, 3);
        if (posx4 >= -5){
            orangeTrack = 13;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 13){
        posz4 += dx;
        ghost(-5,0,posz4 , 0.4, 0, 3);
        if (posz4 >= 0){
            orangeTrack = 14;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 14){
        posx4 += dx;
        ghost(posx4,0,0 , 0.4, 0, 3);
        if (posx4 >= -3){
            orangeTrack = 15;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 15){
        posz4 -= dx;
        ghost(-3,0,posz4 , 0.4, 0, 3);
        if (posz4 <= -3){
            orangeTrack = 16;
        }
        glutIdleFunc(idle);
    }
    else if (orangeTrack == 16){
        posx4 += dx;
        ghost(posx4,0,-3 , 0.4, 0, 3);
        if (posx4 >= 0){
            orangeTrack = 0;
        }
        glutIdleFunc(idle);
    }
    
    // Win condition
    if (score == 132){
        glPopMatrix();
        glDisable(GL_LIGHTING);
        //  Display parameters
        glColor3f(1,1,1);
        glWindowPos2i(400,400);
        Print("Congratulations: You Win");
        pos[0] = 0;
        pos[1] = 0;
    }
    
   // Detect ghost collision
   if ((pos[0] == posx1 && pos[1] == posz1) ||
        (pos[0] == posx2 && pos[1] == posz2) ||
        (pos[0] == posx3 && pos[1] == posz3) ||
        (pos[0] == posx4 && pos[1] == posz4)){
        lives--;
        dead = 1;
        if (lives == 0){
            done = 1;
        }
    }
    // Draw Pacman
    if (dead == 0){
        pacman(pos[0],0,pos[1], .4,0,press);
    }
    else if (done == 1){
        glPopMatrix();
        glDisable(GL_LIGHTING);
        //  Display parameters
        glColor3f(1,1,1);
        glWindowPos2i(400,400);
        Print("Game Over");
        pos[0] = 0;
        pos[1] = 0;
    }
    else{
        pos[0] = 0;
        pos[1] = 0;
        dead = 0;
        pacman(pos[0],0,pos[1], .4,0,press);
        glutPostRedisplay();
    }

   glPopMatrix();
   glDisable(GL_LIGHTING);
   //  Display parameters
   glColor3f(1,1,1);
   glWindowPos2i(5,5);
   Print("Lives:%i Score=%i",lives,score);
   //  Render the scene and make it visible
   glFlush();
   glutSwapBuffers();
}