X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fpong%2FMatch.cpp;h=6de4b03423d5ce4414a2208dd65ef63bea930b91;hb=HEAD;hp=683defe191eb9c154d564de9abf0922694d9563c;hpb=d6f654935eaa4994e95ce71740e30f917c29e7c3;p=sdl-test7.git diff --git a/src/pong/Match.cpp b/src/pong/Match.cpp index 683defe..6de4b03 100644 --- a/src/pong/Match.cpp +++ b/src/pong/Match.cpp @@ -26,18 +26,25 @@ 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) -, paddleSpeed(150) +, 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, 10)) -, bottomWall(Entity::Vector(800, 10)) +, topWall(Entity::Vector(800, 20)) +, bottomWall(Entity::Vector(800, 20)) , leftWall(Entity::Vector(10, 480)) , rightWall(Entity::Vector(10, 480)) , entities() @@ -49,13 +56,29 @@ Match::Match(void) } ball.SetPosition(Entity::Vector(400, 240)); - ball.SetVelocity(Entity::Vector(180, 180)); - ball.SetMaxVelocity(500.0f); + ball.SetVelocity(Entity::Vector(190, 190)); + ball.SetMaxVelocity(750.0f); secondBall.SetPosition(Entity::Vector(300, 240)); - secondBall.SetVelocity(Entity::Vector(-20, -20)); + secondBall.SetVelocity(Entity::Vector(-100, -100)); secondBall.SetMaxVelocity(600.0f); + thirdBall.SetPosition(Entity::Vector(250, 440)); + 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)); @@ -65,7 +88,7 @@ Match::Match(void) leftPaddle.SetStatic(); rightPaddle.SetStatic(); - topWall.SetPosition(Entity::Vector(0, -10)); + topWall.SetPosition(Entity::Vector(0, -20)); rightWall.SetPosition(Entity::Vector(800, 0)); bottomWall.SetPosition(Entity::Vector(0, 480)); leftWall.SetPosition(Entity::Vector(-10, 0)); @@ -75,9 +98,13 @@ Match::Match(void) bottomWall.SetStatic(); leftWall.SetStatic(); - entities.reserve(8); + 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); @@ -204,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; @@ -217,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); } }