Пример #1
0
int main()
{
    //window properties
    sf::RenderWindow pong(sf::VideoMode(RENDERWIDTH, RENDERHEIGHT, 32), "GameName", sf::Style::Fullscreen);
    pong.setMouseCursorVisible(false);
    pong.setFramerateLimit(60);

    //music
    sf::Music bgm;
    bgm.openFromFile("multimedia/audio/musica.wav");
    bgm.setPitch(1);
    bgm.setLoop(true);
    bgm.play();

    //sound
    sf::SoundBuffer buffer1;
    buffer1.loadFromFile("multimedia/audio/bounce.wav");
    sf::Sound bounce;
    bounce.setBuffer(buffer1);
    sf::SoundBuffer buffer2;
    buffer2.loadFromFile("multimedia/audio/point.wav");
    sf::Sound point;
    point.setBuffer(buffer2);

    //ncp properties
    sf::RectangleShape ncp(sf::Vector2f(5, RENDERHEIGHT / 1.6));
    ncp.setFillColor(sf::Color(50, 50, 50));
    ncp.setPosition(RENDERWIDTH / 2, RENDERHEIGHT / 2 - (RENDERHEIGHT / 1.6) / 2 );

    //player 1 properties
    int p1Len = 100;
    sf::RectangleShape player1(sf::Vector2f(10, p1Len));
    player1.setFillColor(sf::Color(0, 0, 255));
    player1.setPosition(0, RENDERHEIGHT / 2 - player1.getSize().y / 2);
    int player1Score = 0;

    //player 2 properties
    int p2Len = 100;
    sf::RectangleShape player2(sf::Vector2f(10, p2Len));
    player2.setFillColor(sf::Color(255, 0, 0));
    player2.setPosition(RENDERWIDTH - player2.getSize().x, RENDERHEIGHT / 2 - player2.getSize().y / 2);
    int player2Score = 0;

    //ball properties
    sf::CircleShape ball(10, 25);
    ball.setFillColor(sf::Color(255, 255, 255));
    ball.setPosition(RENDERWIDTH / 2 - ball.getRadius(), RENDERHEIGHT / 2 - ball.getRadius());
    float BALLSPEED = 2;
    float ballVelX = -BALLSPEED, ballVelY = -BALLSPEED;
    float ballX = RENDERWIDTH / 2 - ball.getRadius(), ballY = RENDERHEIGHT / 2 - ball.getRadius();
    float ballDiameter = ball.getRadius() * 2;

    //score-timer text
    sf::Font font;
    font.loadFromFile("fonts/LiberationSerif-Regular.ttf");
    sf::Text score1("0", font, 80);
    score1.setPosition(RENDERWIDTH / 4, 0);
    sf::Text score2("0", font, 80);
    score2.setPosition(3 * RENDERWIDTH / 4 - score2.getLocalBounds().width, 0);
    sf::Text timer1("", font, 80);
    timer1.setPosition(0 , 5 * RENDERHEIGHT / 6);
    sf::Text timer2("", font, 80);
    timer2.setPosition(RENDERWIDTH / 2 - timer2.getLocalBounds().width, 5 * RENDERHEIGHT / 6);
    int time1 = 0;
    int time2 = 0;

    //gameover
    sf::Text gameover("GAME OVER", font, 120);
    gameover.setColor(sf::Color::Red);
    gameover.setPosition(0, RENDERHEIGHT / 3);


    //game loop
    while(player1Score + player2Score != 3)
    {
        sf::Event event;
        while(pong.pollEvent(event))
        {
            if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
                pong.close();
        }


        //score for player one winning
        if(player1Score == player2Score + 1)
        {
            timer1.setString(convertInt(time1 += 2));
            timer2.setString(convertInt(time2 += 1));
        }

        if(player1Score == player2Score + 2)
        {
            timer1.setString(convertInt(time1 += 4));
            timer2.setString(convertInt(time2 += 1));
        }

        if(player1Score == player2Score + 3)
        {
            timer1.setString(convertInt(time1 += 8));
            timer2.setString(convertInt(time2 += 1));
        }

        if(player1Score == player2Score + 4)
        {
            timer1.setString(convertInt(time1 += 16));
            timer2.setString(convertInt(time2 += 1));
        }

        if(player1Score == player2Score + 5)
        {
            timer1.setString(convertInt(time1 += 32));
            timer2.setString(convertInt(time2 += 1));
        }

        if(player1Score == player2Score + 6)
        {
            timer1.setString(convertInt(time1 += 64));
            timer2.setString(convertInt(time2 += 1));
        }

        //score on equals
        if(player1Score == player2Score)
        {
            timer1.setString(convertInt(time1 += 1));
            timer2.setString(convertInt(time2 += 1));
        }

        //score for player two winning
        if(player2Score == player1Score + 1)
        {
            timer2.setString(convertInt(time2 += 2));
            timer1.setString(convertInt(time1 += 1));
        }

        if(player2Score == player1Score + 2)
        {
            timer2.setString(convertInt(time2 += 4));
            timer1.setString(convertInt(time1 += 1));
        }

        if(player2Score == player1Score + 3)
        {
            timer2.setString(convertInt(time2 += 8));
            timer1.setString(convertInt(time1 += 1));
        }

        if(player2Score == player1Score + 4)
        {
            timer2.setString(convertInt(time2 += 16));
            timer1.setString(convertInt(time1 += 1));
        }

        if(player2Score == player1Score + 5)
        {
            timer2.setString(convertInt(time2 += 32));
            timer1.setString(convertInt(time1 += 1));
        }

        if(player2Score == player1Score + 6)
        {
            timer2.setString(convertInt(time2 += 64));
            timer1.setString(convertInt(time1 += 1));
        }

        //player 1 movement
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
            player1.move(0, -10);
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
            player1.move(0, 10);

        //player 2 movement
        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            player2.move(0, -10);
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            player2.move(0, 10);

        //player 1 and wall collision
        if(player1.getPosition().y <= 0)
            player1.setPosition(0, 0);
        if(player1.getPosition().y >= RENDERHEIGHT - player1.getSize().y)
            player1.setPosition(0, RENDERHEIGHT - player1.getSize().y);

        //player 2 and wall collision
        if(player2.getPosition().y <= 0)
            player2.setPosition(RENDERWIDTH - player2.getSize().x, 0);
        if(player2.getPosition().y >= RENDERHEIGHT - player2.getSize().y)
            player2.setPosition(RENDERWIDTH - player2.getSize().x, RENDERHEIGHT - player2.getSize().y);

        //ball and wall collision
        if(ball.getPosition().y <= 0 || ball.getPosition().y >= RENDERHEIGHT - ballDiameter)
        {
            ballVelY *= -1;
            bounce.play();
        }

        //ball and player 1 collision
        if (ball.getPosition().x <= player1.getPosition().x + player1.getSize().x)
        {
            if ((ball.getPosition().y + ballDiameter >= player1.getPosition().y
                    && ball.getPosition().y + ballDiameter <= player1.getPosition().y + player1.getSize().y)
                    || ball.getPosition().y <= player1.getPosition().y + player1.getSize().y
                    && ball.getPosition().y >= player1.getPosition().y)
            {
                ballVelX = (ballVelX - 1) * -1;
                bounce.play();
            }
            else
            {
                point.play();
                player2Score += 1;
                ballX = RENDERWIDTH / 2 - ball.getRadius();
                if (BALLSPEED < 8)
                    BALLSPEED += 0.5;
                ballVelX = BALLSPEED;
                score2.setString(convertInt(player2Score));
                score2.setPosition(3 * RENDERWIDTH / 4 - score2.getLocalBounds().width, 0);
                if (p2Len > 30)
                    p2Len -= 10;
                player2.setSize(sf::Vector2f(10, p2Len));
                if (p1Len < 80)
                    p1Len += 10;
                player1.setSize(sf::Vector2f(10, p1Len));
            }
        }

        //ball and player 2 collision
        if (ball.getPosition().x + ballDiameter >= player2.getPosition().x)
        {
            if ((ball.getPosition().y + ballDiameter >= player2.getPosition().y
                    && ball.getPosition().y + ballDiameter <= player2.getPosition().y + player2.getSize().y)
                    || ball.getPosition().y <= player2.getPosition().y + player2.getSize().y
                    && ball.getPosition().y >= player2.getPosition().y)
            {
                ballVelX = (ballVelX + 1) * -1;
                bounce.play();
            }
            else
            {
                point.play();
                player1Score += 1;
                ballX = RENDERWIDTH / 2 - ball.getRadius();
                if (BALLSPEED < 8)
                    BALLSPEED += 0.5;
                ballVelX = -BALLSPEED;
                score1.setString(convertInt(player1Score));
                if (p1Len > 30)
                    p1Len -= 10;
                player1.setSize(sf::Vector2f(10, p1Len));
                if (p2Len < 80)
                    p2Len += 10;
                player2.setSize(sf::Vector2f(10, p2Len));
            }
        }

        //ball position update
        ballX += ballVelX;
        ballY += ballVelY;
        ball.setPosition(ballX, ballY);

        //render updates
        pong.clear();
        pong.draw(score1);
        pong.draw(timer1);
        pong.draw(timer2);
        pong.draw(score2);
        pong.draw(player1);
        pong.draw(player2);
        pong.draw(ball);
        pong.draw(ncp);
        pong.display();

        while(player1Score + player2Score == 3)
        {
            if(player1Score > player2Score)
                timer1.setString(convertInt(time1 += 10000));
            if(player1Score < player2Score)
                timer2.setString(convertInt(time2 += 10000));

            pong.clear(sf::Color::Black);
            pong.draw(score1);
            pong.draw(timer1);
            pong.draw(timer2);
            pong.draw(score2);
            pong.draw(gameover);
            pong.display();

            counter(3);
            break;
        }

    }

    std::stringstream ss;
    ss.str (timer1.getString());
    std::string scorePlayer1 = ss.str();
    ss.str (timer2.getString());
    std::string scorePlayer2 = ss.str();
    std::cout << "Final Score:" << '\n';
    std::cout << "Player1: " + scorePlayer1 << '\n';
    std::cout << "Player2: " + scorePlayer2 << '\n';


    std::ofstream myfile ("highscores.txt", std::ofstream::in | std::ofstream::out | std::ofstream::app);
    if (myfile.is_open())
    {
        myfile << scorePlayer1 << std::endl;
        myfile << scorePlayer2 << std::endl;
        myfile.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}
Пример #2
0
int main(){
  
////////////////////GAME PROPERTIES///////////////////////////////////

	//window properties
	sf::RenderWindow pong(sf::VideoMode(RENDERWIDTH, RENDERHEIGHT, 32), "Tungu");
	pong.setMouseCursorVisible(false);
	pong.setFramerateLimit(60);

	//music
	sf::Music bgm;
	bgm.openFromFile("multimedia/audio/background.wav");
	bgm.setPitch(1.5);
	bgm.setLoop(true);
	bgm.play();

	//sound
	sf::SoundBuffer buffer1;
	buffer1.loadFromFile("multimedia/audio/bounce.wav");
	sf::Sound bounce;
	bounce.setBuffer(buffer1);
	sf::SoundBuffer buffer2;
	buffer2.loadFromFile("multimedia/audio/point.wav");
	sf::Sound point;
	point.setBuffer(buffer2);
	
	//ncp properties
	sf::RectangleShape ncp(sf::Vector2f(5, RENDERHEIGHT / 1.6));
	ncp.setFillColor(sf::Color(50, 50, 50));
	ncp.setPosition(RENDERWIDTH / 2, RENDERHEIGHT / 2 - (RENDERHEIGHT / 1.6) / 2 );

	//player 1 properties
	int p1Len = 100;
	sf::RectangleShape player1(sf::Vector2f(15, p1Len));
	player1.setFillColor(sf::Color(0, 0, 255));
	player1.setPosition(0, RENDERHEIGHT / 2 - player1.getSize().y / 2);
	int player1Score = 0;

	//player 2 properties
	int p2Len = 100;
	sf::RectangleShape player2(sf::Vector2f(15, p2Len));
	player2.setFillColor(sf::Color(0, 255, 0));
	player2.setPosition(RENDERWIDTH - player2.getSize().x, RENDERHEIGHT / 2 - player2.getSize().y / 2);
	int player2Score = 0;

	//ball properties
	sf::CircleShape ball(10, 25);
	ball.setFillColor(sf::Color(255, 255, 255));
	ball.setPosition(RENDERWIDTH / 2 - ball.getRadius(), RENDERHEIGHT / 2 - ball.getRadius());
	float BALLSPEED = 15;
	float ballVelX = -BALLSPEED, ballVelY = -BALLSPEED;
	float ballX = RENDERWIDTH / 2 - ball.getRadius(), ballY = RENDERHEIGHT / 2 - ball.getRadius();
	float ballDiameter = ball.getRadius() * 2;
	
	//score-timer text
	sf::Font font;
	font.loadFromFile("fonts/LiberationSerif-Regular.ttf");
	sf::Text score1("0", font, 80);
	score1.setPosition(RENDERWIDTH / 4, 0);
	sf::Text score2("0", font, 80);
	score2.setPosition(3 * RENDERWIDTH / 4 - score2.getLocalBounds().width, 0);
	sf::Text timer1("", font, 50);
	timer1.setPosition(0 , 5 * RENDERHEIGHT / 6);
	sf::Text timer2("", font, 50);
	timer2.setPosition(RENDERWIDTH / 2 - timer2.getLocalBounds().width, 5 * RENDERHEIGHT / 6);
	int time1 = 0;
	int time2 = 0;
	
	//gameover
	sf::Text gameover("GAME OVER", font, 120);
	gameover.setColor(sf::Color::Red);
	gameover.setPosition(0, RENDERHEIGHT / 3);
	
		
	///////////////CAMERA FUNTIONS//////////////////////

      CvCapture* capture =0;   
    
      capture = cvCaptureFromCAM(0);


     	 if(!capture){

		printf("Capture failure\n");

		return -1;
      }
      
      IplImage* frame=0;

      frame = cvQueryFrame(capture);  
         
      if(!frame) return -1;
  
     //create a blank image and assigned to 'imgTracking' which has the same size of original video

     imgTracking=cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U, 3);

     cvZero(imgTracking); //covert the image, 'imgTracking' to black

     //cvNamedWindow("Player1"); 
    
     ///cvNamedWindow("Player2");

      //iterate through each frames of the video
     
      while(player1Score + player2Score != 7){

		frame = cvQueryFrame(capture); 
          
		if(!frame) break;

		frame=cvCloneImage(frame); 
            
		cvSmooth(frame, frame, CV_GAUSSIAN,3,3); //smooth the original image using Gaussian kernel

			/////////////////// Player 1 ////////////////////

			IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 

			cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV

			IplImage* imgThresh = GetThresholdedImage(imgHSV, 85, 143, 40, 116, 256, 159); //guante cyan
	 
			cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel
	    
			player100 =  trackObject(imgThresh, 255, 0, 0, 1);

			/////////////////// Player 2 ////////////////////

			IplImage* imgHSV2 = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 
	    
			cvCvtColor(frame, imgHSV2, CV_BGR2HSV);//Change the color format from BGR to HSV

			IplImage* imgThresh2 = GetThresholdedImage(imgHSV2, 26, 145, 31, 73, 256, 111); //guante verde

 			cvSmooth(imgThresh2, imgThresh2, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel

			player200 = trackObject(imgThresh2, 0, 255, 0, 2);

            	// Add the tracking image and the frame

		cvAdd(frame, imgTracking, frame);

		//cvShowImage("Player1", imgThresh);
 
		//cvShowImage("Player2", imgThresh2); 
		
		cvMoveWindow("Video", 1800, 0);

		cvResizeWindow("Video", 100, 240);
           
		cvShowImage("Video", frame);
           
           //Clean up used images

           cvReleaseImage(&imgHSV);

	   cvReleaseImage(&imgHSV2);

           cvReleaseImage(&imgThresh);

	   cvReleaseImage(&imgThresh2);   
          
           cvReleaseImage(&frame);

            //Wait 10mS
            int c = cvWaitKey(10);

            //If 'ESC' is pressed, break the loop
            if((char)c==27 ) break;  


/////////////////////////////Scores///////////////////////////////////

		//score for player one winning
		if(player1Score == player2Score + 1)
		{
		    timer1.setString(convertInt(time1 += 2));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		if(player1Score == player2Score + 2)
		{
		    timer1.setString(convertInt(time1 += 4));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		if(player1Score == player2Score + 3)
		{
		    timer1.setString(convertInt(time1 += 8));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		if(player1Score == player2Score + 4)
		{
		    timer1.setString(convertInt(time1 += 16));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		if(player1Score == player2Score + 5)
		{
		    timer1.setString(convertInt(time1 += 32));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		if(player1Score == player2Score + 6)
		{
		    timer1.setString(convertInt(time1 += 64));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		//score on equals
		if(player1Score == player2Score)
		{
		    timer1.setString(convertInt(time1 += 1));
		    timer2.setString(convertInt(time2 += 1));
		}
		
		//score for player two winning
		if(player2Score == player1Score + 1)
		{
		    timer2.setString(convertInt(time2 += 2));
		    timer1.setString(convertInt(time1 += 1));
		}
		
		if(player2Score == player1Score + 2)
		{
		    timer2.setString(convertInt(time2 += 4));
		    timer1.setString(convertInt(time1 += 1));
		}
		
		if(player2Score == player1Score + 3)
		{
		    timer2.setString(convertInt(time2 += 8));
		    timer1.setString(convertInt(time1 += 1));
		}
		
		if(player2Score == player1Score + 4)
		{
		    timer2.setString(convertInt(time2 += 16));
		    timer1.setString(convertInt(time1 += 1));
		}
		
		if(player2Score == player1Score + 5)
		{
		    timer2.setString(convertInt(time2 += 32));
		    timer1.setString(convertInt(time1 += 1));
		}
		
		if(player2Score == player1Score + 6)
		{
		    timer2.setString(convertInt(time2 += 64));
		    timer1.setString(convertInt(time1 += 1));
		}

//////////////////////////////Game////////////////////////////////////

		//player 1 movement muy lento
		
		if(player100==6)
			
			player1.move(0, -(vel-3));

		else if(player100==-6)

			player1.move(0, vel-3);

		//player 1 movement LENTO	
		
		if(player100==1)
			
			player1.move(0, -vel);

		else if(player100==-1)

			player1.move(0, vel);


		//player 1 movement MEDIO
		
		if(player100==2)
			
			player1.move(0, -(vel+10));

		else if(player100==-2)

			player1.move(0, vel+10);

		//player 1 movement RAPIDO
		
		if(player100==3)
			
			player1.move(0, -(vel+20));

		else if(player100==-3)

			player1.move(0, vel+20);

		//player 1 movement muy rapido
		
		if(player100==4)
			
			player1.move(0, -(vel+25));

		else if(player100==-4)

			player1.move(0, vel+25);

		//player 1 movement Extreme
		
		if(player100==5)
			
			player1.move(0, -(vel+30));

		else if(player100==-5)

			player1.move(0, vel+30);

		
		//MOVIMIENTO GOLPE PLAYER1

		if(player100==0)

			player1.move(0,0);
			
		
	
		if (player1.getPosition().x <= 10){

		if(player100==22)
			
			player1.move(10, 0);
			
			
		}


		//player 2 movement muy LENTO

		if(player200==6)

			player2.move(0, -(vel-3));

		else if(player200==-6)

			player2.move(0, vel-3);

		//player 2 movement LENTO

		if(player200==1)

			player2.move(0, -vel);

		else if(player200==-1)

			player2.move(0, vel);

		//player 2 movement MEDIO

		if(player200==2)

			player2.move(0, -(vel+10));

		else if(player200==-2)

			player2.move(0, vel+10);

		//player 2 movement RAPIDO

		if(player200==3)

			player2.move(0, -(vel+20));

		else if(player200==-3)

			player2.move(0, vel+20);

		//player 2 movement muy rapido

		if(player200==4)

			player2.move(0, -(vel+25));

		else if(player200==-4)

			player2.move(0, vel+25);

		//player 2 movement Extreme

		if(player200==5)
			player2.move(0, -(vel+30));

		else if(player200==-5)

			player2.move(0, vel+30);

		
		if(player200==0) 

			player2.move(0,0);

		//MOVIMIENTO GOLPE PLAYER2
		
		if (player2.getPosition().x >= RENDERWIDTH-player2.getSize().x-10){
			  
		if(player200==-22)
			
			player2.move(-10, 0);
			
			
		}

		//player 1 and wall collision

		if(player1.getPosition().y <= 0)

			player1.setPosition(0, 0);

		if(player1.getPosition().y >= RENDERHEIGHT - player1.getSize().y)

			player1.setPosition(0, RENDERHEIGHT - player1.getSize().y);

		//PLAYER1 AND WALL BACK COLLISION

		if(player1.getPosition().x != 0)

			player1.move(-1,0);
		
		//PLAYER2 AND WALL BACK COLLISION

		if(player2.getPosition().x != RENDERWIDTH-player2.getSize().x)

			player2.move(1,0);
		
		//player 2 and wall collision

		if(player2.getPosition().y <= 0)

			player2.setPosition(RENDERWIDTH - player2.getSize().x, 0);

		if(player2.getPosition().y >= RENDERHEIGHT - player2.getSize().y)

			player2.setPosition(RENDERWIDTH - player2.getSize().x, RENDERHEIGHT - player2.getSize().y);

		//ball and wall collision

		if(ball.getPosition().y <= 0 || ball.getPosition().y >= RENDERHEIGHT - ballDiameter){


			ballVelY *= -1;

			bounce.play();

		}

		//ball and player 1 collision

		if (ball.getPosition().x <= player1.getPosition().x + player1.getSize().x){


			if ((ball.getPosition().y + ballDiameter >= player1.getPosition().y && ball.getPosition().y + ballDiameter <= player1.getPosition().y + player1.getSize().y) || ball.getPosition().y <= player1.getPosition().y + player1.getSize().y && ball.getPosition().y >= player1.getPosition().y){


	if (player1.getPosition().x > 14){

				ballVelX = (ballVelX - 5) * -1;

				ball.setFillColor(sf::Color(255,0,0));

				
			}

	else if (player1.getPosition().x <= 14){

				ballVelX = (ballVelX - 3) * -1;

				ball.setFillColor(sf::Color(0,0,255));

				bounce.play();
}
			

			}

			else{
				ball.setFillColor(sf::Color(255,255,255));

				point.play();

				player2Score += 1;  

				ballX = RENDERWIDTH / 2 - ball.getRadius();

				if (BALLSPEED < 8)

					BALLSPEED += 0.2;

				ballVelX = BALLSPEED;

				score2.setString(convertInt(player2Score));

				score2.setPosition(3 * RENDERWIDTH / 4 - score2.getLocalBounds().width, 0);

				if (p2Len > 40)

					p2Len -= 10;

				player2.setSize(sf::Vector2f(15, p2Len));

				if (p1Len < 100)

					p1Len += 10;

				player1.setSize(sf::Vector2f(15, p1Len));
				
			}
		}

		//ball and player 2 collision

		if (ball.getPosition().x + ballDiameter >= player2.getPosition().x){

		
			if ((ball.getPosition().y + ballDiameter >= player2.getPosition().y && ball.getPosition().y + ballDiameter <= player2.getPosition().y + player2.getSize().y) || ball.getPosition().y <= player2.getPosition().y + player2.getSize().y && ball.getPosition().y >= player2.getPosition().y){
			


				if (player2.getPosition().x < (RENDERWIDTH-9-player2.getSize().x)){

					ballVelX = (ballVelX + 5) * -1;

					ball.setFillColor(sf::Color(255,0,0));

					
				
				}

				else if (player2.getPosition().x >= (RENDERWIDTH-9-player2.getSize().x)){

					ballVelX = (ballVelX + 3) * -1;

					ball.setFillColor(sf::Color(0,255,0));

					bounce.play();
			}
		}
				
			
				else{
			
					ball.setFillColor(sf::Color(255,255,255));

					point.play();

					player1Score += 1;

					ballX = RENDERWIDTH / 2 - ball.getRadius();

					if (BALLSPEED < 8)

						BALLSPEED += 0.5;

					ballVelX = -BALLSPEED;

					score1.setString(convertInt(player1Score));

					if (p1Len > 40)
						p1Len -= 10;

					player1.setSize(sf::Vector2f(15, p1Len));

					if (p2Len < 100)

						p2Len += 10;

					player2.setSize(sf::Vector2f(15, p2Len));
			}
		}

		//ball position update
		ballX += ballVelX;
		ballY += ballVelY;
		ball.setPosition(ballX, ballY);

		//render updates
		
		pong.clear();
		pong.draw(score1);
		pong.draw(timer1);
		pong.draw(timer2);
		pong.draw(score2);
		pong.draw(player1);
		pong.draw(player2);
		pong.draw(ball);
		pong.draw(ncp);
		pong.display();


		while(player1Score + player2Score == 7){

			if(player1Score > player2Score)
				timer1.setString(convertInt(time1 += 500));
			if(player1Score < player2Score)
				timer2.setString(convertInt(time2 += 500));
		
			pong.clear(sf::Color::Black);
			pong.draw(score1);
			pong.draw(timer1);
			pong.draw(timer2);
			pong.draw(score2);
			pong.draw(gameover);
			pong.display();

			counter(3);
			break;
		}

/////////////////////Finish Game/////////////////////////////////


    
      }

	std::stringstream ss;
	ss.str (timer1.getString());
	std::string scorePlayer1 = ss.str();
	ss.str (timer2.getString());
	std::string scorePlayer2 = ss.str();
	std::cout << "Final Score:" << '\n';
	std::cout << "Player1: " + scorePlayer1 << '\n';
	std::cout << "Player2: " + scorePlayer2 << '\n';

	
	std::ofstream myfile ("highscores.txt", std::ofstream::in | std::ofstream::out | std::ofstream::app);
  	if (myfile.is_open())
  	{
  		myfile << scorePlayer1 << std::endl;
    		myfile << scorePlayer2 << std::endl;
    		myfile.close();
  	}

  	else std::cout << "Unable to open file";

      cvDestroyAllWindows() ;
      cvReleaseImage(&imgTracking);
      cvReleaseCapture(&capture);     

      return 0;
}
void BlueCoreDeviceController_newStyle::Implementation::checkQueues ()
{
    PDU pdu(null_pdu);
    for ( int i = 0 ; i < PDU::csr_hci_extensions_count ; ++i )
    {
        for ( int j = 0 ; j < 8 && pending[i]->getNextIfAvailable(pdu) ; ++j )
        {
            mConnectionToChip->sendpdu ( pdu );
            if (pdu.channel() == PDU::hciACL)
                aclDataTracker.removeData(pdu);
        }
    }
    // deal with packets coming up...
    for ( int j = 0 ; j < 8 && upstream.get( pdu ) ; ++j )
    {
        PDU::bc_channel ch = pdu.channel();

        switch ( ch )
        {
        case PDU::bccmd:
            pending[PDU::bccmd]->setToken();
            break;
        case PDU::hq :
        {
            if ( HQ_PDU(pdu).get_req_type() == HQPDU_SETREQ )
            {
                HQ_PDU ret ( pdu.clone () );
                ret.set_req_type ( HQPDU_GETRESP );
                pending[PDU::hq]->add(sae(ret,no_call_back));
            }
            break;
        }
        case PDU::hciCommand:
        {
            HCIEventPDU ev ( pdu );
            switch ( ev.get_event_code() )
            {
            case HCI_EV_NUMBER_COMPLETED_PKTS:
            {
                HCI_EV_NUMBER_COMPLETED_PKTS_T_PDU ncp( pdu );
                uint8 count = ncp.get_num_handles();
                for ( uint8 i = 0 ; i < count ; ++i )
                {
                    uint16 handle;
                    uint16 tokens;
                    ncp.get_num_completed_pkts(i,handle,tokens);
                    pending[PDU::hciACL]->incToken(tokens);
                }
            }
                break;
            case HCI_EV_COMMAND_COMPLETE:
            {
                HCICommandCompletePDU cc (pdu);
                pending[PDU::hciCommand]->setToken(cc.get_num_hci_command_pkts() );
                switch(cc.get_op_code())
                {
                case HCI_READ_VOICE_SETTING:
                {
                    HCI_READ_VOICE_SETTING_RET_T_PDU rvs(pdu);
                    if ( rvs.get_status() == HCI_SUCCESS )
                    {
                        bool is_it_16 = (rvs.get_voice_setting()
                                       & HCI_VOICE_SAMP_SIZE_MASK)
                                      == HCI_VOICE_SAMP_SIZE_16BIT;
                        scoBandwidthTracker.set_audio_sample_size ( is_it_16 ? 16 : 8 );
                    }
                }
                    break;
                case HCI_READ_BUFFER_SIZE:
                    if ( !initialised_ACL_flow_control )
                    {
                        HCI_READ_BUFFER_SIZE_RET_T_PDU rbs ( pdu );
                        if ( rbs.get_status() == HCI_SUCCESS )
                        {
                            initialised_ACL_flow_control = true;
                            pending[PDU::hciACL]->setToken ( rbs.get_total_acl_data_pkts() );
                        }
                    }
                    break;
                }
            }
                break;
            case HCI_EV_COMMAND_STATUS:
            {
                HCI_EV_COMMAND_STATUS_T_PDU cc (pdu);
                pending[PDU::hciCommand]->setToken(cc.get_num_hci_command_pkts() );
                if (cc.get_op_code() == HCI_ADD_SCO_CONNECTION
                 && cc.get_status() != HCI_COMMAND_CURRENTLY_PENDING )
                {
                    getTransport()->set_sco_bandwidth(scoBandwidthTracker.decrease());
                }
            }
                break;
            case HCI_EV_CONN_COMPLETE:
            {
                HCI_EV_CONN_COMPLETE_T_PDU cc(pdu);
                if (cc.get_status() == HCI_SUCCESS)
                {
                    if (cc.get_link_type() == HCI_LINK_TYPE_ACL)
                        aclDataTracker.addConnection(cc.get_handle());
                    else
                    {
                        // sco or esco.  This will glitch if we were the initiating end.
                        getTransport()->set_sco_bandwidth(scoBandwidthTracker.consolidate(cc.get_handle()));
                    }
                }
                else
                {
                    if (cc.get_link_type() == HCI_LINK_TYPE_SCO)
                    {
                        getTransport()->set_sco_bandwidth(scoBandwidthTracker.decrease());
                    }
                }
            }
                break;
            case HCI_EV_DISCONNECT_COMPLETE:
            {
                HCI_EV_DISCONNECT_COMPLETE_T_PDU dc(pdu);
                if ( dc.get_status() == HCI_SUCCESS )
                {
                    uint16 h = dc.get_handle();
                    if (aclDataTracker.usingConnection(h))
                        aclDataTracker.removeConnection(h);
                    else
                    {
                        // sco or esco
                        getTransport()->set_sco_bandwidth(scoBandwidthTracker.decrease(h));
                    }
                }
            }
                break;
            case HCI_EV_SYNC_CONN_COMPLETE:
            {
                HCI_EV_SYNC_CONN_COMPLETE_T_PDU scc(pdu);
                if ( scc.get_status() == HCI_SUCCESS )
                {
                    // sco or esco.  This will glitch if we were the initiating end.
                    getTransport()->set_sco_bandwidth(scoBandwidthTracker.consolidate(scc.get_handle()));
                }
                else
                    scoBandwidthTracker.decrease();
            }
                break;
            case HCI_EV_LOOPBACK_COMMAND:
                // we just had a command loop back, so allow us to send another.
                pending[PDU::hciCommand]->setToken(1);
                break;
            default:
                break;
            }
            break;
        }
        default:
            break;
        }

        if ( !pending[ch]->run_callback(pdu) )
            mReceiver.onPDU ( pdu );
        //  some stuff should be passed up... HQ and HCI only?
        if ( mConnectionOnOffer )
        {
            switch ( ch )
            {
            case PDU::hq:
            case PDU::hciCommand:
            case PDU::hciACL:
            case PDU::hciSCO:
                (void)sendUp ( pdu );
                break;
            default:
                // do nothing
                break;
            }
        }
    }
    //  accept requests from higher layers on all channels.
    for ( int k = 0 ; k < 8 && downstream.get( pdu ) ; ++k )
    {
        switch ( pdu.channel() )
        {
        case PDU::hciCommand:
        case PDU::hciACL:
        case PDU::hciSCO:
            (void)send ( sae ( pdu , perm_no_pass ) , true );
            break;
        default:
            (void)send ( sae ( pdu , perm_pass_up ) , true );
            break;
        }
    }
}