static void* mainloop(void* arg) { for(int ct=0;; ct++) { pthread_mutex_lock(&readlock); Tree* tree=Tree::make(cin); if(!cin) { pthread_mutex_unlock(&readlock); break; } pthread_mutex_unlock(&readlock); if(!tree->label)continue; tree->label=rootSym; Indicies gold; Indicies yield; tree->yield(yield); if(yield.size()>=MAXLEN)continue; goldLabs(tree, gold); Sent snt(yield); Trellis trel(snt); int tc=score2(gold,trel.multiresult); pthread_mutex_lock(&writelock); totTags+=trel.sz; totCorrect+=tc; pthread_mutex_unlock(&writelock); } }
/// Tests the Constructors /// @return True if all tests were executed, false if not bool ScoreTestSuite::TestCaseConstructor() { //------Last Checked------// // - Jan 6, 2005 // TEST CASE: Default Constructor { Score score; TEST(wxT("Default Constructor"), (score.GetGuitarCount() == 0) && (score.GetChordDiagramCount() == 0) && (score.GetFloatingTextCount() == 0) && (score.GetGuitarInCount() == 0) && (score.GetTempoMarkerCount() == 0) && (score.GetDynamicCount() == 0) && (score.GetAlternateEndingCount() == 0) && (score.GetSystemCount() == 0) ); } // TEST CASE: Copy Constructor { Score score; score.m_guitarArray.Add(new Guitar); score.m_chordDiagramArray.Add(new ChordDiagram); score.m_floatingTextArray.Add(new FloatingText); score.m_guitarInArray.Add(new GuitarIn); score.m_tempoMarkerArray.Add(new TempoMarker); score.m_dynamicArray.Add(new Dynamic); score.m_alternateEndingArray.Add(new AlternateEnding); score.m_systemArray.Add(new System); Score score2(score); TEST(wxT("Copy Constructor"), score2 == score); } return (true); }
/** \brief logs one record to disk * Logs one record to disk which may come from different sources * (direct from tlf or from other instance via LAN) * * \param from_lan true - Log lanmessage, false - normal message */ int log_to_disk(int from_lan) { extern char hiscall[]; extern char comment[]; extern char my_rst[]; extern char his_rst[]; extern char last_rst[4]; extern char qsonrstr[5]; extern char lan_logline[]; extern int rit; extern int trx_control; extern int cqmode; #ifdef HAVE_LIBHAMLIB extern freq_t outfreq; #else extern int outfreq; #endif extern int block_part; extern char lan_message[]; extern char thisnode; extern int lan_mutex; extern int cqwwm2; extern int no_rst; pthread_mutex_lock(&disk_mutex); if (!from_lan) { // qso from this node addcall(); /* add call to dupe list */ makelogline(); store_qso(logline4); // send qso to other nodes...... send_lan_message(LOGENTRY, logline4); if (trx_control && (cqmode == S_P)) addspot(); /* add call to bandmap if in S&P and no need to ask for frequency */ hiscall[0] = '\0'; /* reset the call string */ comment[0] = '\0'; /* reset the comment string */ strncpy(last_rst, his_rst, sizeof(last_rst)); /* remember last report */ his_rst[1] = '9'; /* restore RST to 599 */ my_rst[1] = '9'; } else { // qso from lan strncpy(lan_logline, lan_message + 2, 87); strcat(lan_logline, " "); if (cqwwm2 == 1) { if (lan_logline[0] != thisnode) lan_logline[79] = '*'; } lan_logline[87] = '\0'; total = total + score2(lan_logline); addcall2(); store_qso(lan_logline); } if (from_lan) lan_mutex = 2; else lan_mutex = 1; scroll_log(); lan_mutex = 0; attron(modify_attr(COLOR_PAIR(NORMCOLOR))); /* erase comment field */ if (!from_lan) mvprintw(12, 54, " "); attron(COLOR_PAIR(C_LOG) | A_STANDOUT); if (!from_lan) { mvprintw(7, 0, logline0); mvprintw(8, 0, logline1); mvprintw(9, 0, logline2); } mvprintw(10, 0, logline3); mvprintw(11, 0, logline4); refreshp(); attron(COLOR_PAIR(C_WINDOW)); mvprintw(12, 23, qsonrstr); if (no_rst) { mvaddstr(12, 44, "---"); mvaddstr(12, 49, "---"); } else { mvaddstr(12, 44, his_rst); mvaddstr(12, 49, my_rst); } sync(); if ((rit == 1) && (trx_control == 1)) outfreq = RESETRIT; block_part = 0; /* unblock use partials */ pthread_mutex_unlock(&disk_mutex); return (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; }
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; }
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("bgm.wav"); bgm.setPitch(1.5); bgm.setLoop(true); bgm.play(); //sound sf::SoundBuffer buffer1; buffer1.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam.wav"); sf::Sound bounce; bounce.setBuffer(buffer1); sf::SoundBuffer buffer2; buffer2.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam2.wav"); sf::Sound point; point.setBuffer(buffer2); //player 1 properties int p1Len = 80; 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 = 150; sf::RectangleShape player2(sf::Vector2f(10, p2Len)); player2.setFillColor(sf::Color(255, 50, 50)); 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; //BONUS properties /* sf::CircleShape bonus(10, 25); ball.setFillColor(sf::Color(0,255,0)); ball.setPosition(RENDERWIDTH / 2 , RENDERHEIGHT / rand ()%10+1); float BONUSSPEED = 2; float bonusVelX = -BONUSSPEED, bonusVelY = -BONUSSPEED; float bonusX = RENDERWIDTH / 2 - bonus.getRadius(), bonusY = RENDERHEIGHT / 2 - bonus.getRadius(); float bonusDiameter = bonus.getRadius() * 2; */ //score text sf::Font font; font.loadFromFile("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Bold.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); //game loop while(pong.isOpen()) { sf::Event event; while(pong.pollEvent(event)) { if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) pong.close(); } //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); } //MOVIMIENTO GOLPE PLAYER1 if (player1.getPosition().x <= 10){ if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){ player1.move(10, 0); }} //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); //MOVIMIENTO GOLPE PLAYER2 if (player2.getPosition().x >= RENDERWIDTH-player2.getSize().x-10){ if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ 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) { ballVelX = (ballVelX - 1) * -1; ball.setFillColor(sf::Color(0,255,0)); bounce.play(); } else { 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 > 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; ball.setFillColor(sf::Color(255,0,0)); 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(score2); pong.draw(player1); pong.draw(player2); pong.draw(ball); pong.display(); } return 0; }
int main(){ ////////////////////GAME PROPERTIES/////////////////////////////////// //window properties sf::RenderWindow pong(sf::VideoMode(RENDERWIDTH, RENDERHEIGHT, 32), "GameName"); pong.setMouseCursorVisible(false); pong.setFramerateLimit(60); //music sf::Music bgm; bgm.openFromFile("musica.wav"); bgm.setPitch(1.5); bgm.setLoop(true); bgm.play(); //sound sf::SoundBuffer buffer1; buffer1.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam.wav"); sf::Sound bounce; bounce.setBuffer(buffer1); sf::SoundBuffer buffer2; buffer2.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam2.wav"); sf::Sound point; point.setBuffer(buffer2); sf::SoundBuffer buffer3; buffer3.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam.wav"); //perfecti hit!!!!! sf::Sound perfecthit; perfecthit.setBuffer(buffer3); //player 1 properties int p1Len = 80; 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 = 80; 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(7, 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; sf::Font font; font.loadFromFile("/usr/share/cups/fonts/FreeMonoOblique.ttf"); font.loadFromFile("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Bold.ttf"); sf::Text score1("0", font, 80); score1.setPosition(RENDERWIDTH / 4, 0); sf::Text score2("0", font, 80); score2.setPosition(3 * RENDERWIDTH / 4, 0); ///////////////FINISH PROPERTIES////////////////////////////////////////////////////// CvCapture* capture =0; capture = cvCaptureFromCAM(1); 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("Video"); cvNamedWindow("Ball"); //iterate through each frames of the video while(true){ frame = cvQueryFrame(capture); if(!frame) break; frame=cvCloneImage(frame); cvSmooth(frame, frame, CV_GAUSSIAN,3,3); //smooth the original image using Gaussian kernel 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, 94, 169, 127, 143, 251, 229); cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel player100 = trackObject(imgThresh, 255, 0, 0, 1); IplImage* imgHSV2 = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); cvCvtColor(frame, imgHSV2, CV_BGR2HSV); IplImage* imgThresh2 = GetThresholdedImage(imgHSV2, 22, 64, 152, 50, 134, 256); 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("Ball", imgThresh); cvShowImage("Ball2", imgThresh2); 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; //////////////////////////////Game//////////////////////////////////// //player 1 movement if(player100==1){ player1.move(0, -10);} else if(player100==-1){ player1.move(0, 10); } //MOVIMIENTO GOLPE PLAYER1 if(player100==0){ player1.move(0,0);} if (player1.getPosition().x <= 10){ if(player100==2){ player1.move(10, 0); }} //player 2 movement if(player200==1) player2.move(0, -10); else if(player200==-1) player2.move(0, 10); if(player200==0){ player2.move(0,0);} //MOVIMIENTO GOLPE PLAYER2 if (player2.getPosition().x >= RENDERWIDTH-player2.getSize().x-10){ if(player200==-2){ 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 - 2) * -1; ball.setFillColor(sf::Color(255,0,0)); perfecthit.play(); } else if (player1.getPosition().x <= 14){ ballVelX = (ballVelX - 1) * -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 + 2) * -1; ball.setFillColor(sf::Color(255,0,0)); perfecthit.play(); } else if (player2.getPosition().x >= (RENDERWIDTH-9-player2.getSize().x)){ ballVelX = (ballVelX + 1) * -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(score2); pong.draw(player1); pong.draw(player2); pong.draw(ball); pong.display(); /////////////////////Finish Game///////////////////////////////// } cvDestroyAllWindows() ; cvReleaseImage(&imgTracking); cvReleaseCapture(&capture); return 0; }
int main() { //window properties sf::RenderWindow pong(sf::VideoMode(RENDERWIDTH, RENDERHEIGHT, 32), "GameName"); //, sf::Style::Fullscreen pong.setMouseCursorVisible(false); pong.setFramerateLimit(24); /* //music sf::Music bgm; bgm.openFromFile("musica.wav"); bgm.setPitch(1.5); bgm.setLoop(true); bgm.play(); */ //sound sf::SoundBuffer buffer1; buffer1.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam.wav"); sf::Sound bounce; bounce.setBuffer(buffer1); sf::SoundBuffer buffer2; buffer2.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam2.wav"); sf::Sound point; point.setBuffer(buffer2); sf::SoundBuffer buffer3; buffer3.loadFromFile("/usr/lib/libreoffice/share/gallery/sounds/beam.wav"); //perfecti hit!!!!! sf::Sound perfecthit; perfecthit.setBuffer(buffer3); //player 1 properties int p1Len = 80; 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 = 80; 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(7, 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; sf::Font font; font.loadFromFile("/usr/share/cups/fonts/FreeMonoOblique.ttf"); font.loadFromFile("/usr/share/fonts/truetype/ttf-liberation/LiberationSerif-Bold.ttf"); sf::Text score1("0", font, 80); score1.setPosition(RENDERWIDTH / 4, 0); sf::Text score2("0", font, 80); score2.setPosition(3 * RENDERWIDTH / 4, 0); //game loop //while(pong.isOpen()) /////////////////////Declaraciones//////////////////////////////// IplImage* frame=0; IplImage* imgTracking; CvCapture* capture =0; IplImage* imgThresh; IplImage* imgThresh2; sf::Event event; int player100=0; int player200=0; capture = cvCaptureFromCAM(1); for(int i=0;i<1000;++i) { if(!capture){ printf("Capture failure\n"); return -1; } frame = cvRetrieveFrame(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); cvSmooth(frame, frame, CV_GAUSSIAN,3,3); //smooth the original image using Gaussian kernel IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV imgThresh = GetThresholdedImage(imgHSV, 24, 0, 224, 46, 89, 256); cvReleaseImage(&imgHSV); delete(imgHSV); cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel player100 = trackObject(imgThresh, 255, 0, 0, 1); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// IplImage* imgHSV2 = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); cvCvtColor(frame, imgHSV2, CV_BGR2HSV); imgThresh2 = GetThresholdedImage(imgHSV2, 24, 0, 224, 46, 89, 256); cvReleaseImage(&imgHSV2); delete(imgHSV2); cvSmooth(imgThresh2, imgThresh2, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel player200 = trackObject(imgThresh2, 0, 255, 0, 2); /* //player 1 movement if( player100 == 1 ) { player1.move(0, -10);} else if(player100==-1){ player1.move(0, 10); } //MOVIMIENTO GOLPE PLAYER1 if (player1.getPosition().x <= 10){ if(player100==2){ player1.move(10, 0); }} //player 2 movement if(player200==1) player2.move(0, -10); else if(player200==-1) player2.move(0, 10); //MOVIMIENTO GOLPE PLAYER2 if (player2.getPosition().x >= RENDERWIDTH-player2.getSize().x-10){ if(player200==-2){ 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 - 2) * -1; ball.setFillColor(sf::Color(255,0,0)); perfecthit.play(); } else if (player1.getPosition().x <= 14){ ballVelX = (ballVelX - 1) * -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)); } }//fin IF //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 + 2) * -1; ball.setFillColor(sf::Color(255,0,0)); perfecthit.play(); } else if (player2.getPosition().x >= (RENDERWIDTH-9-player2.getSize().x)){ ballVelX = (ballVelX + 1) * -1; ball.setFillColor(sf::Color(0,255,0)); bounce.play(); }//fin if elseh } 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 < 10) p2Len += 10; player2.setSize(sf::Vector2f(15, p2Len)); }//fin else }//fin IF */ //ball position update ballX += ballVelX; ballY += ballVelY; ball.setPosition(ballX, ballY); //render updates pong.clear(); pong.draw(score1); pong.draw(score2); pong.draw(player1); pong.draw(player2); pong.draw(ball); pong.display(); }//fin for cvReleaseCapture(&capture); cvReleaseImage(&imgThresh); cvReleaseImage(&imgThresh2); cvReleaseImage(&frame); cvReleaseImage(&imgTracking); //cvReleaseImage(&imgTemp); revisar este puntero delete(moments); return 0; }