]> git.localhorst.tv Git - sdl-test7.git/blobdiff - src/pong/Match.cpp
added some comments
[sdl-test7.git] / src / pong / Match.cpp
index 229a8fce034fd127c9303956e613d9b33099bb8c..6de4b03423d5ce4414a2208dd65ef63bea930b91 100644 (file)
@@ -26,15 +26,21 @@ namespace pong {
 
 Match::Match(void)
 : ctrl(0)
-, scoreFont(TTF_OpenFont("data/font/Magra-Regular.ttf", 30))
+, scoreFont(TTF_OpenFont("data/font/Magra-Regular.ttf", 24))
 , leftScoreText(0)
 , rightScoreText(0)
+, topScoreText(0)
+, bottomScoreText(0)
+, totalScoreText(0)
 , paddleSpeed(250)
 , worldWidth(800)
 , worldHeight(480)
 , ball(10)
 , secondBall(7)
 , thirdBall(7)
+, fourthBall(8)
+, fifthBall(9)
+, sixthBall(11)
 , leftPaddle(Entity::Vector(10, 100))
 , rightPaddle(Entity::Vector(10, 100))
 , topWall(Entity::Vector(800, 20))
@@ -61,6 +67,18 @@ Match::Match(void)
        thirdBall.SetVelocity(Entity::Vector(100, 100));
        thirdBall.SetMaxVelocity(600.0f);
 
+       fourthBall.SetPosition(Entity::Vector(550, 250));
+       fourthBall.SetVelocity(Entity::Vector(100, 100));
+       fourthBall.SetMaxVelocity(600.0f);
+
+       fifthBall.SetPosition(Entity::Vector(340, 250));
+       fifthBall.SetVelocity(Entity::Vector(100, 100));
+       fifthBall.SetMaxVelocity(600.0f);
+
+       sixthBall.SetPosition(Entity::Vector(550, 350));
+       sixthBall.SetVelocity(Entity::Vector(100, 100));
+       sixthBall.SetMaxVelocity(600.0f);
+
        leftPaddle.SetPosition(Entity::Vector(0, 200));
        rightPaddle.SetPosition(Entity::Vector(790, 280));
 
@@ -80,10 +98,13 @@ Match::Match(void)
        bottomWall.SetStatic();
        leftWall.SetStatic();
 
-       entities.reserve(9);
+       entities.reserve(12);
        entities.push_back(&ball);
        entities.push_back(&secondBall);
        entities.push_back(&thirdBall);
+//     entities.push_back(&fourthBall);
+//     entities.push_back(&fifthBall);
+//     entities.push_back(&sixthBall);
        entities.push_back(&leftPaddle);
        entities.push_back(&rightPaddle);
        entities.push_back(&topWall);
@@ -210,12 +231,27 @@ void Match::RenderScore(SDL_Surface *screen) {
 
        dest.x = screen->w - rightScoreText->w - 2;
        SDL_BlitSurface(rightScoreText, 0, screen, &dest);
+
+//     dest.x = 2;
+//     dest.y = screen->h - topScoreText->h - 2;
+//     SDL_BlitSurface(topScoreText, 0, screen, &dest);
+//
+//     dest.x = screen->w - bottomScoreText->w - 2;
+//     dest.y = screen->h - bottomScoreText->h - 2;
+//     SDL_BlitSurface(bottomScoreText, 0, screen, &dest);
+//
+//     dest.x = screen->w/2 - totalScoreText->w/2;
+//     dest.y = 2;
+//     SDL_BlitSurface(totalScoreText, 0, screen, &dest);
 }
 
 void Match::UpdateScore(SDL_Surface *screen) {
        if (!scoreFont) return;
        if (leftScoreText) SDL_FreeSurface(leftScoreText);
        if (rightScoreText) SDL_FreeSurface(rightScoreText);
+       if (topScoreText) SDL_FreeSurface(topScoreText);
+       if (bottomScoreText) SDL_FreeSurface(bottomScoreText);
+       if (totalScoreText) SDL_FreeSurface(totalScoreText);
 
        SDL_Color color;
        color.r = 0xFF;
@@ -223,12 +259,24 @@ void Match::UpdateScore(SDL_Surface *screen) {
        color.b = 0xFF;
 
        stringstream s;
-       s << rightWall.HitCount();
+       s << "right: " << rightWall.HitCount();
        leftScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
 
        s.str("");
-       s << leftWall.HitCount();
+       s << "left: " << leftWall.HitCount();
        rightScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+       s.str("");
+       s << "top: " << topWall.HitCount();
+       topScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+       s.str("");
+       s << "bottom: " << bottomWall.HitCount();
+       bottomScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
+
+       s.str("");
+       s << "total: " << rightWall.HitCount() + leftWall.HitCount() + topWall.HitCount() + bottomWall.HitCount();
+       totalScoreText = TTF_RenderUTF8_Blended(scoreFont, s.str().c_str(), color);
 }
 
 }